PERF: Add index `id DESC, baked_version` ON `posts`.
A scheduled job runs `Post.rebake_old` with a limit of 80 which does a look up for the latest posts that have not been baked to the latest version. Before this commit, the query would run using the primary key's index and does a reverse scan. However the query performance quicky becomes bad as more and more of the latest posts have been baked to the latest version.
This commit is contained in:
parent
ca57e18f42
commit
4791d992dc
|
@ -0,0 +1,7 @@
|
|||
class AddIndexIdBakedVersionOnPosts < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_index :posts, [:id, :baked_version],
|
||||
order: { id: :desc },
|
||||
where: "(deleted_at IS NULL)"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue