mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 17:52:45 +08:00
PERF: Add index_for_rebake_old
to posts
.
The index becomes smaller over time and is much faster. Follow up to 4791d992dc484c8b81ec4250c65c097873e2f708.
This commit is contained in:
parent
28d117898f
commit
c82a929025
@ -20,6 +20,7 @@ class Post < ActiveRecord::Base
|
||||
self.plugin_permitted_create_params = {}
|
||||
|
||||
# increase this number to force a system wide post rebake
|
||||
# Recreate `index_for_rebake_old` when the number is increased
|
||||
# Version 1, was the initial version
|
||||
# Version 2 15-12-2017, introduces CommonMark and a huge number of onebox fixes
|
||||
BAKED_VERSION = 2
|
||||
|
@ -0,0 +1,22 @@
|
||||
class AddIndexForRebakeOldOnPosts < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
remove_index :posts, name: :index_posts_on_id_and_baked_version
|
||||
|
||||
add_index :posts, :id,
|
||||
order: { id: :desc },
|
||||
where: "(baked_version IS NULL OR baked_version < 2) AND deleted_at IS NULL",
|
||||
name: :index_for_rebake_old,
|
||||
algorithm: :concurrently
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :posts, name: :index_for_rebake_old
|
||||
|
||||
add_index :posts, [:id, :baked_version],
|
||||
order: { id: :desc },
|
||||
where: "(deleted_at IS NULL)",
|
||||
algorithm: :concurrently
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user