<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Steven C. on Medium]]></title>
        <description><![CDATA[Stories by Steven C. on Medium]]></description>
        <link>https://medium.com/@stevencch?source=rss-1aaa5d14059f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*vKQ5crJZi1AQ_HCY27-TEw.jpeg</url>
            <title>Stories by Steven C. on Medium</title>
            <link>https://medium.com/@stevencch?source=rss-1aaa5d14059f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 05:10:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stevencch/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Easy Fixing File Encoding (in Vim)]]></title>
            <link>https://medium.com/space-cat/easy-fixing-file-encoding-in-vim-9ce0d309cf35?source=rss-1aaa5d14059f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ce0d309cf35</guid>
            <category><![CDATA[encoding]]></category>
            <category><![CDATA[vim]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Steven C.]]></dc:creator>
            <pubDate>Wed, 26 Feb 2020 12:55:03 GMT</pubDate>
            <atom:updated>2020-02-26T12:58:21.369Z</atom:updated>
            <content:encoded><![CDATA[<p>I have received some files from Japanese clients and have trouble with reading it through Vim, it looks like a mess:</p><figure><img alt="The Shift-JIS encoded file looks like a mess in my Vim" src="https://cdn-images-1.medium.com/max/751/1*hGIq3Hwwms31TAzJ2jbk0A.png" /></figure><p>Check the file by file -bicommand, and it returns:</p><figure><img alt="file -bi command and return result" src="https://cdn-images-1.medium.com/max/758/1*aEj_D1nYt9KpccTgcBd4OQ.png" /></figure><p>text/plain; charset=unknown-8bit</p><p>Fortunately, I’ve been informed that the file is encoded by Shift JIS, saved a hell lot of my time to figure out the encoding.</p><p><strong>Shift JIS</strong> (<em>Shift Japanese Industrial Standards, also SJIS, Shift_JIS</em>) is a character encoding for the Japanese language, it has been replaced by CP932 for better compatibility in certain cases.</p><p>According to <a href="https://vim.fandom.com/wiki/Reloading_a_file_using_a_different_encoding">Vim Tips Wiki</a>, one can reload a file using a different encoding if Vim was not able to detect the correct encoding.</p><p>So, here is the simple solution in Vim, just use :e ++enc=sjis or :e ++enc=cp932:</p><figure><img alt="After reload the file by this command, it become readable" src="https://cdn-images-1.medium.com/max/751/1*TVob1D-y66mV0dKaiHXPhg.png" /></figure><h4>References</h4><ul><li><a href="https://en.wikipedia.org/wiki/Shift_JIS">Shift JIS</a> and <a href="https://en.wikipedia.org/wiki/Code_page_932_(Microsoft_Windows)">Code page 932</a> on Wikipedia.</li><li><a href="https://vim.fandom.com/wiki/Reloading_a_file_using_a_different_encoding">Vim Tips Wiki</a></li><li><a href="https://www.stevenchang.tw/blog/2020/02/05/easy-fixing-file-encoding-in-vim">My Blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ce0d309cf35" width="1" height="1" alt=""><hr><p><a href="https://medium.com/space-cat/easy-fixing-file-encoding-in-vim-9ce0d309cf35">Easy Fixing File Encoding (in Vim)</a> was originally published in <a href="https://medium.com/space-cat">From Zen to Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solve apt-get 403 forbidden error in Linux Ubuntu]]></title>
            <link>https://medium.com/@stevencch/solve-apt-get-403-forbidden-error-in-linux-ubuntu-53ca856aacab?source=rss-1aaa5d14059f------2</link>
            <guid isPermaLink="false">https://medium.com/p/53ca856aacab</guid>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Steven C.]]></dc:creator>
            <pubDate>Wed, 21 Aug 2019 15:14:17 GMT</pubDate>
            <atom:updated>2020-01-22T01:57:58.383Z</atom:updated>
            <content:encoded><![CDATA[<p>I&#39;ve been using Ubuntu 16.04 on Oracle VM VirtualBox these days, this morning when I run$ sudo apt-get update to update software, it breaks and I got this error instead:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ic5RUBarpZpCQ0WxrdFzYA.png" /></figure><p>Seems there is an invalid repository that gives 403 error and causes the problem.</p><pre>Err:20 <a href="http://ppa.launchpad.net/moka/stable/ubuntu">http://ppa.launchpad.net/moka/stable/ubuntu</a> xenial/main amd64 Packages 403 Forbidden</pre><p>We can also run $ sudo apt-get update | grep “Failed” to list failing repositories.</p><p>This error will lead other installation process fail, for example like RVM installation, since $ sudo apt-get update doesn’t work well.</p><p><a href="https://www.stevenchang.tw/blog/2019/08/21/Linux_apt-get-update-fail"><strong>Check solution on my personal blog</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53ca856aacab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[文摘]盤古之白]]></title>
            <link>https://medium.com/@stevencch/%E6%96%87%E6%91%98-%E7%9B%A4%E5%8F%A4%E4%B9%8B%E7%99%BD-566d7c7d9b6?source=rss-1aaa5d14059f------2</link>
            <guid isPermaLink="false">https://medium.com/p/566d7c7d9b6</guid>
            <dc:creator><![CDATA[Steven C.]]></dc:creator>
            <pubDate>Wed, 31 Jul 2019 16:10:56 GMT</pubDate>
            <atom:updated>2019-07-31T16:10:56.837Z</atom:updated>
            <content:encoded><![CDATA[<p>身為責任制的『前』受災戶，我一直很看不慣職場上做事隨便、得過且過的廢柴，他們總有世界多的理由詮釋自己的正當性，我就想知道其他認真的人憑什麼跟著被拖累？</p><h4><a href="https://www.stevenchang.tw/blog/2019/07/20/Auto_spacing"><strong>全文連結</strong></a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=566d7c7d9b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[文摘] 2 步驟完成模糊搜尋 Search for whatever I LIKE in Rails]]></title>
            <link>https://medium.com/@stevencch/%E6%96%87%E6%91%98-2-%E6%AD%A5%E9%A9%9F%E5%AE%8C%E6%88%90%E6%A8%A1%E7%B3%8A%E6%90%9C%E5%B0%8B-search-for-whatever-i-like-in-rails-25fd28366331?source=rss-1aaa5d14059f------2</link>
            <guid isPermaLink="false">https://medium.com/p/25fd28366331</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Steven C.]]></dc:creator>
            <pubDate>Fri, 19 Jul 2019 15:12:19 GMT</pubDate>
            <atom:updated>2019-07-19T15:12:19.373Z</atom:updated>
            <content:encoded><![CDATA[<p>在對資料庫做查詢時，為了達成模式比對（關鍵字查詢），我們會用到語法中的 LIKE 和 ILIKE 運算子， LIKE 是標準的 SQL 語法，ILIKE 則是 PostgreSQL 額外提供的實用功能，能夠忽略英文大小寫。</p><p>再搭配萬用字元(wildcard)組成模糊相似條件查詢比較相同的內容，如此便完成模糊搜尋功能。</p><h4><a href="https://www.stevenchang.tw/blog/2019/07/19/Rails_SQL-ILIKE_Search">詳全文</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25fd28366331" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[文摘]Rails 上傳圖片超簡單 To upload images via CarrierWave, Amazon S3 and Figaro]]></title>
            <link>https://medium.com/@stevencch/%E6%96%87%E6%91%98-rails-%E4%B8%8A%E5%82%B3%E5%9C%96%E7%89%87%E8%B6%85%E7%B0%A1%E5%96%AE-to-upload-images-via-carrierwave-amazon-s3-and-figaro-34947980a3dc?source=rss-1aaa5d14059f------2</link>
            <guid isPermaLink="false">https://medium.com/p/34947980a3dc</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[s3]]></category>
            <dc:creator><![CDATA[Steven C.]]></dc:creator>
            <pubDate>Fri, 19 Jul 2019 15:09:53 GMT</pubDate>
            <atom:updated>2019-07-19T15:09:53.386Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>透過 <a href="https://github.com/carrierwaveuploader/carrierwave">CarrierWave</a> 套件上傳圖片到 <a href="https://aws.amazon.com/tw/s3/">Aamzon S3</a>(Simple Storage Service)</li><li>用 <a href="https://github.com/laserlemon/figaro">Figaro</a> 管理金鑰等機敏資訊</li><li>利用 <a href="https://github.com/minimagick/minimagick">MiniMagick</a> 指定圖片尺寸</li></ul><h4><a href="https://www.stevenchang.tw/blog/2019/07/16/CarrierWave_and_AWS_S3">詳全文</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34947980a3dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[文摘]AJAX on Rails 透過 remote: true 實作 AJAX 按鈕]]></title>
            <link>https://medium.com/@stevencch/%E6%96%87%E6%91%98-ajax-on-rails-%E9%80%8F%E9%81%8E-remote-true-%E5%AF%A6%E4%BD%9C-ajax-%E6%8C%89%E9%88%95-ea51cd98ca4f?source=rss-1aaa5d14059f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea51cd98ca4f</guid>
            <dc:creator><![CDATA[Steven C.]]></dc:creator>
            <pubDate>Fri, 19 Jul 2019 15:07:09 GMT</pubDate>
            <atom:updated>2019-07-19T15:07:09.440Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.stevenchang.tw/blog/2019/07/11/AJAX_on_Rails">在什麼是 AJAX? 一文中，已大略介紹過 AJAX 和其應用場景， 本篇記錄如何在 Rails 專案中實作 AJAX 按鈕。</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea51cd98ca4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[文摘]什麼是 AJAX？]]></title>
            <link>https://medium.com/@stevencch/%E6%96%87%E6%91%98-%E4%BB%80%E9%BA%BC%E6%98%AF-ajax-2e19a43095e1?source=rss-1aaa5d14059f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e19a43095e1</guid>
            <category><![CDATA[ajax]]></category>
            <dc:creator><![CDATA[Steven C.]]></dc:creator>
            <pubDate>Fri, 19 Jul 2019 15:05:40 GMT</pubDate>
            <atom:updated>2019-07-19T15:05:40.742Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.stevenchang.tw/blog/2019/07/10/What_is_ajax"><em>一種網頁的互動方式，在用戶無需重新載入整個網頁的情況下，就能夠更新網頁部分的內容。</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e19a43095e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[網誌搬家。]]></title>
            <link>https://medium.com/@stevencch/%E7%B6%B2%E8%AA%8C%E6%90%AC%E5%AE%B6-969ad67a17d9?source=rss-1aaa5d14059f------2</link>
            <guid isPermaLink="false">https://medium.com/p/969ad67a17d9</guid>
            <dc:creator><![CDATA[Steven C.]]></dc:creator>
            <pubDate>Fri, 19 Jul 2019 14:58:52 GMT</pubDate>
            <atom:updated>2019-07-19T17:31:51.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*yqAaGe7Qtd3SGPqCqUIQYw.jpeg" /><figcaption>新網誌，<a href="https://www.stevenchang.tw/">有閒來坐</a></figcaption></figure><h3>網誌搬家 ｜自己網站自己架</h3><p>畢竟我愛著自己的<a href="https://www.stevenchang.tw/blog/2019/05/05/Make-your-editor-punk-in-a-synthwave-way">編輯器</a>。</p><h4><a href="https://www.stevenchang.tw/">有閒來坐</a></h4><p>每次寫完文章再貼到 Medium 都需要調整版面覺得心有點兒累，好歹我下週開始也是個網頁開發工程師✌️，故決定自己動手用 <a href="https://jekyllrb.com/">Jekyll</a> 架設了部落格，克服了技術難題之後，以下幾點是我想自架：</p><ol><li>個人部落格可以自訂網址，功能就像名片一樣能塑造專業形象</li><li>隨心所欲訂製自己喜歡的風格、顏色、字型等</li><li>可以自己搞 SEO，埋 GA 分析流量等等操作練習</li><li>使用 Markdown 語法<strong>高效</strong>、<strong>優雅地</strong>撰寫和發佈文章</li><li>更好的分類功能</li><li>自主權</li></ol><p>當然 Medium 也有許多優點，只是這幾點是我更在乎的地方。</p><p>而在看到這篇《<a href="https://www.webdistortion.com/2019/05/16/can-we-all-please-stop-using-medium-now/?source=post_page---------------------------"><em>Can we all please stop using Medium now?</em></a><em>》</em>後，更是激起心中的認同：</p><blockquote><em>Please. It’s 2019. Learn to market yourself and your content. Quit being lazy waiting for Medium to do it for you. </em><strong><em>OWN YOUR PLATFORM</em></strong><em>.</em></blockquote><p>寫技術文章主要希望能系統化地整理自己所學，如果能順便對社群帶來一絲絲貢獻那就太好啦！</p><h4>延伸閱讀：</h4><p>《<a href="https://medium.com/@hulitw/freecodecamp-hackernoon-are-leaving-medium-1b7319d7a8a7">Medium 出走潮：freeCodeCamp 與 Hacker Noon 相繼離開，為什麼？</a>》by <a href="https://medium.com/u/f1fb3e40dc37">Huli</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=969ad67a17d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[企業參訪] PicCollage 拼貼趣]]></title>
            <link>https://medium.com/space-cat/%E4%BC%81%E6%A5%AD%E5%8F%83%E8%A8%AA-piccollage-%E6%8B%BC%E8%B2%BC%E8%B6%A3-a6297cefe9f4?source=rss-1aaa5d14059f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6297cefe9f4</guid>
            <dc:creator><![CDATA[Steven C.]]></dc:creator>
            <pubDate>Sun, 09 Jun 2019 15:16:09 GMT</pubDate>
            <atom:updated>2019-06-09T15:58:59.247Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jU-2DsIDWaMStyDcRgYc4g.jpeg" /></figure><blockquote>200,000,000+ 的下載量是什麼概念？</blockquote><p>要企及如此瘋狂的下載量，<a href="https://cardinalblue.com/">PicCollage</a> 必須得放眼全世界。目前 App 主要使用者來自美國、英國及日本等國家。面對全球化的競爭，團隊在空間和時間上的跨度甚至涵蓋三個不同的時區，該怎樣合理的協調工作也變成棘手的挑戰之一。</p><p>身為台灣第一支下載量破一億次的 App，PicCollage 交出了漂亮的成績單，但他們並不滿足止步於此，持續不斷地在整合 VR、Machine Learning、Computer Vision 等等新技術，致力於打造讓世界變得更加歡樂的產品，無疑也是我們本土新創產業值得借鏡的對象。</p><p>很高興有這樣的機會，透過<a href="https://5xruby.tw/"><em>五倍紅寶石</em></a>的安排，來到這麼有活力的跨國企業實地參訪。席間共同創辦人很大方的和我們分享他們這幾年發展下來觀察到的經驗以及對市場的看法，其中提到一點特別讓我印象深刻：</p><blockquote>不分地區的用戶，一年當中有個共同<strong>最活躍</strong>使用他們家服務的時間</blockquote><p>猜得到是什麼時候嗎？</p><p>答案就是 — —『<strong>母親節</strong>』，這說明了即便在不同的國度，人的本質並沒有太大改變，消費需求都是一樣的（母愛的偉大也是放諸四海皆準的）。抓住了這個重點，再來就是考驗團隊如何維持發展的動力和敏銳度，能不能像 PicCollage 起步的最初一樣，挖掘到市場的潛在需求並且把握住時機？</p><p>今次我們有幸參與每週五舉辦的『內部工作坊』，就是他們的秘訣之一。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rxbufrJf-2vRneZ4tz52FQ.jpeg" /><figcaption>團隊成員有許多外籍同仁，工作坊採全英語進行</figcaption></figure><p>看見一位又一位的開發者興奮地分享他們的心得，在台下的我也不自覺感染現場的熱情，幻想著身邊也能有許多這樣的夥伴，真心喜愛著自己做的事情，一起在往卓越的路上並肩前行。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t1AdVjhbzWDuzDEFrCxQ3g.jpeg" /><figcaption>參訪合照</figcaption></figure><blockquote>在此祝福有緣的讀者諸君們也都能找到</blockquote><blockquote>自己喜愛的、值得投身奉獻的事物 🙌</blockquote><h3>特別感謝：</h3><ul><li><a href="https://cardinalblue.com/">PicCollage</a></li><li><a href="https://5xruby.tw/"><em>五倍紅寶石</em></a></li><li>感謝 PicCollage — <a href="https://www.jimytc.com/?fbclid=IwAR3yRZevDmk0HqowdDm56D4oD2YIwggWFMxixpTjTlJOKrIqCNjTBBE16AY">陳彥廷</a> 前輩提供職涯發展的提點</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6297cefe9f4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/space-cat/%E4%BC%81%E6%A5%AD%E5%8F%83%E8%A8%AA-piccollage-%E6%8B%BC%E8%B2%BC%E8%B6%A3-a6297cefe9f4">[企業參訪] PicCollage 拼貼趣</a> was originally published in <a href="https://medium.com/space-cat">From Zen to Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Rails] 透過計數快取 Counter Cache 提升效能]]></title>
            <link>https://medium.com/space-cat/rails-%E9%80%8F%E9%81%8E%E8%A8%88%E6%95%B8%E5%BF%AB%E5%8F%96-counter-cache-%E6%8F%90%E5%8D%87%E6%95%88%E8%83%BD-f9cc61318502?source=rss-1aaa5d14059f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9cc61318502</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Steven C.]]></dc:creator>
            <pubDate>Sun, 09 Jun 2019 08:43:02 GMT</pubDate>
            <atom:updated>2019-06-09T09:15:44.933Z</atom:updated>
            <content:encoded><![CDATA[<p>在許多場合需要統計 has_many 一對多關聯的資料數量，若使用單純的 Rails 關聯查詢，則每次讀取頁面都會重新再統計一次，影響網站效能。</p><h3>情境</h3><p>專案Project model has many 任務Task.</p><p>Project model</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf5f9cecc6dbef2305af5c4384399a18/href">https://medium.com/media/bf5f9cecc6dbef2305af5c4384399a18/href</a></iframe><p>projects_controller.rb</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93edf41445315410f3792e9cfe8c88ab/href">https://medium.com/media/93edf41445315410f3792e9cfe8c88ab/href</a></iframe><p>views/projects/index.html.erb</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bffd8af54710f89a31dbe51ee975010b/href">https://medium.com/media/bffd8af54710f89a31dbe51ee975010b/href</a></iframe><p>讀取頁面時就會出現 N+1 Query 問題，1 個專案若有 3 個任務便會做 3 + 1 次查詢：SELECT “tasks”.* FROM “tasks” WHERE “tasks”.”project_id” = ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g0xa5I3DTjz0qCuKYo3sFw.jpeg" /><figcaption>N + 1 Query</figcaption></figure><h3>使用方法</h3><p>在 projects table 中建立 tasks_count 欄位，將計數存在其中，<br>更新專案的任務數量時，counter cache 會同步更新到對應的欄位裡面。</p><h4>建立 migration</h4><p>rails g migration add_tasks_count</p><p>編輯剛建立的 migration 檔：</p><blockquote><em>在程式碼第一行加入 # frozen_string_literal: true 凍結此檔，可以稍微加快往後的讀取速度。</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/155795218310b6682af7ce368a3a40e5/href">https://medium.com/media/155795218310b6682af7ce368a3a40e5/href</a></iframe><p>執行 rails db:migrate</p><h4>編輯 Task model</h4><p>開啟 counter cache:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80cf4d0c59a758c05888b5fc6800b3d0/href">https://medium.com/media/80cf4d0c59a758c05888b5fc6800b3d0/href</a></iframe><p>如果想指定其他欄位儲存 counter cache 請改寫為</p><p>counter_cache: ‘COLUMN_NAME’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*mofqtYMzoIQMsLZFC_10tg.jpeg" /><figcaption>指定 vote 欄位作為紀錄用</figcaption></figure><p>確認資料表內容 schema.rb</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f001774d74db429085b1d87a221075d/href">https://medium.com/media/4f001774d74db429085b1d87a221075d/href</a></iframe><h4>建立 rake task 更新 counter cache</h4><p>更新既有 projects 的 tasks count lib/tasks/update_tasks_count.rb</p><blockquote>這邊使用我在<a href="https://5xruby.tw/">五倍紅寶石</a>學到的技巧，將這段 rake task 整理在 namespace db 之下。</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23dce9e5bf66b15ed77f60c3206ac956/href">https://medium.com/media/23dce9e5bf66b15ed77f60c3206ac956/href</a></iframe><p>查看指令確認一下沒有寫錯：rails -T</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*FWZtEUGwVe3jbrVIirNryQ.jpeg" /><figcaption>$ rails -T</figcaption></figure><p>執行 rails db:updste_tasks</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*rPr9CH7A9xenQActw0cPIw.jpeg" /><figcaption>$ rails db:updste_tasks</figcaption></figure><h4>重啟伺服器</h4><p>再次讀取頁面查看 SQL queries 只剩一行： SELECT “projects”.* FROM “projects”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*Dt9fSABZs7SSRgBYf-6PJQ.jpeg" /><figcaption>禮成，奏樂！</figcaption></figure><blockquote>大功告成！</blockquote><h3>參考資料：</h3><ul><li>五倍紅寶石 <a href="https://kaochenlong.com/">@高見龍</a></li><li><a href="https://ihower.tw/rails/performance.html">Ruby on Rails 實戰聖經</a></li><li><a href="https://rubyplus.com/articles/3221-Counter-Cache-Column-in-Rails-5">Counter Cache Column in Rails 5</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9cc61318502" width="1" height="1" alt=""><hr><p><a href="https://medium.com/space-cat/rails-%E9%80%8F%E9%81%8E%E8%A8%88%E6%95%B8%E5%BF%AB%E5%8F%96-counter-cache-%E6%8F%90%E5%8D%87%E6%95%88%E8%83%BD-f9cc61318502">[Rails] 透過計數快取 Counter Cache 提升效能</a> was originally published in <a href="https://medium.com/space-cat">From Zen to Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>