MySQL 5.7.26 修復了一個 bug #2596684(release note),Aurora MySQL 在 2.10.3(release note)也修復了這個 bug。
最近遇到了一個案例是,有個使用 includes 去 preload association 的地方,相對於直接 pluck 出來,花的時間慢的異常多。研究之後發現是 bullet 的 unused_eager_loading_enable 偵測打開後,會一定程度的影響效能。
includes
unused_eager_loading_enable
如同這位開發者在 issue 所做的說明。unused_eager_loading_enable 有個 O(N²) 複雜度的運算。
最近遇到一個案例,用戶明明有登入,但是打 API 時,卻因為沒有登入而噴錯。
在追查 HTTP Request/Response 時,眼尖的同事發現 Request Headers 根本沒有帶上 cookies,所以伺服器因為沒有 session 登入的資訊,所以才會當成 Client 端還沒登入。但奇怪的是 Client 端的網頁明明就是登入狀態。還有另一個線索是用戶的 Chrome 瀏覽器是很舊的版本。
前陣子與公司的其他夥伴一起找出了偶發的 CORS 原因,紀錄一下
Ruby 3.0.0 在去年聖誕節推出,release note 提到了一些 concurrency 相關的新功能,一邊研究一邊做個紀錄
在 Ruby 3.0.0 Released 提到了 Ruby 針對 Concurrency 加入了 Fiber#scheduler 的新功能,讓 Fiber 可以實作出 Non-blocking 的操作。
Fiber#scheduler
Fiber
終於有時間來研究這件事要怎麼做到,後來研究出最簡單的解法是這樣
偶然發現,Arel 好像是用 visitor pattern,好奇心驅使之下,就來研究看看。
團隊最近遇到一個 subquery + update_all 會鎖整張表的問題,花了一點時間研究
注意:以下為 MySQL 5.6 的實驗探討,在 MySQL 8.0.21 的這個機制已經被優化了
串接 Rollbar 的好處是可以方便監控伺服器噴錯。但是在使用 whenever 排程時執行程式時,有辦法在噴錯時也寫到 Rollbar 嗎?
如果是使用 sidekiq,無論是使用 include Sidekiq::Worker 產生的 worker,或是使用 sidekiq 當成 queue_adapter 的 ActiveJob,Rollbar 都有串接。另外像是 rake 也是有串接的。詳細可以參考 plugins 原始碼以及文件。
sidekiq
include Sidekiq::Worker
queue_adapter
ActiveJob
之前想要寫有條件的 left join 都會寫成 raw SQL query 的字串,但是其實也可以用 Arel 寫出比較好看的程式碼。
假設有個 DB 的 schema 長這樣:
記錄一下照著官方教學設定開發 rails core repository 的環境
以下步驟取自 https://github.com/rails/rails-dev-box:
覺得 Ctrl + R 的 reverse-i-search 用的不是很習慣,google 了一下原來這樣設定就可以用 up/down 鍵搜尋了。
新增 ~/.inputrc 檔案,裡面設定:
~/.inputrc
"\e[A": history-search-backward"\e[B": history-search-forward
來看看這個 CVE-2020–15169 漏洞是怎麼回事
這次讀書會看了這部紀錄片《The Social Dilemma》,中譯《智能社會:進退兩難》,記錄一下觀看心得。
這部電影在描述像是 Facebook 這種社群軟體,他的商業模式是廣告曝光,所以軟體為了讓用戶黏著度提升,會推薦用戶喜歡、認同的貼文。但是這樣的方式會讓用戶只看到某一個面向的貼文,例如你支持的政治議題會頻繁出現,但是你卻不容易看到另一邊的意見。久而久之,你可能會覺得,那些跟你立場不同的人都是笨蛋,讓社會之間出現一種溝通的阻礙。
最近遇到一個因為 splat argument 導致噴 SystemStackError 的案例,研究了半天發現是使用 method_missing 才會遇到
最近工作上遇到一個案例,是呼叫某個函式會噴 SystemStackError,google 發現了類似的事情 https://github.com/redis/redis-rb/issues/264
看〈為你自己學 Ruby on Rails〉介紹 Rack 的 Middleware 執行順序看不太懂,於是就研究了一下原始碼,看看是怎麼回事
因為常常聽到 Middleware Middleware 的,但是又不太懂,於是在網路上找到龍哥寫的文章,非常簡顯易懂,跟著動手做可以知道 Rack 要怎麼使用。
看到 Spotify 有支援另外一種 Authorization Code Flow,叫做 Authorization Code Flow with Proof Key for Code Exchange (PKCE),來玩玩看
心血來潮想玩看看 KKBOX 的 Open API,也一起測試了 Spotify 的部分。這次主要是試試看 OAuth 2.0 Authorization Code Flow 的授權流程,過程都是利用 Postman 來操作。
之前在看 searchkick 的 Github README 時,一直搞不懂 field 這個單位到底是什麼,於是花了一點時間來研究, gem 本人在此:
在 Rails server 沒有重開的情況下,更動資料庫表的欄位預設值,會有意想不到的事情發生
以下是用 Rails 6.0.3.2 + MySQL 5.6 實驗
有一張 tasks 表,有個欄位 completed,預設值為 false,且不能為 NULL
tasks
completed
false
NULL
The pry gem changed itsPry::Prompt API since v0.13.0, and deprecated setting prompt through Pry.config.prompt = [] . If you have customized this way, you should use the new API instead.
Pry::Prompt
Pry.config.prompt = []
[MySQL] 對不存在的 row 加鎖,會造成 Deadlock
CREATE TABLE `users` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4…
如果網站正在 migrate 時,剛好遇到一個 transaction 沒有結束,就算只是 SELECT ,也有可能讓網站倒站。
某個沒有經驗的工程師 A:
對 users table 做一些簡單的查詢,但是開啟了 transaction 沒有 commit
users
BEGIN;SELECT * FROM users;...