I noticed that in ActiveRecord::Core
, when we cache the StatementCache
values (here and there), we potentially duplicate cache entries in the case where both Model.find(1)
and Model.find_by(id: 1)
are called, this results in two entries in the cache, with the respective keys "id"
and ["id"]
I was playing with it and wrote a small patch that prevents that by extracting the first (and only) value from the array of keys, if there’s only one key, in the find_by case.
https://github.com/rails/rails/compare/main...pjambet:pj/reduce-find-by-cache-misses?expand=1