mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 15:43:16 +08:00
PERF: ensure sidebar section link index is correctly ordered (#20854)
We perform lookups on sidebar section links based on sidebar_section_id totally ignoring user. This ensures we have an index to work with. This removes the previous index `links_user_id_section_id_position` which partially doubled up `idx_unique_sidebar_section_links`
This commit is contained in:
parent
c912c58d6c
commit
7038540af6
|
@ -47,7 +47,7 @@ end
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
# idx_sidebar_section_links_on_sidebar_section_id (sidebar_section_id,user_id,position) UNIQUE
|
||||||
# idx_unique_sidebar_section_links (user_id,linkable_type,linkable_id) UNIQUE
|
# idx_unique_sidebar_section_links (user_id,linkable_type,linkable_id) UNIQUE
|
||||||
# index_sidebar_section_links_on_linkable_type_and_linkable_id (linkable_type,linkable_id)
|
# index_sidebar_section_links_on_linkable_type_and_linkable_id (linkable_type,linkable_id)
|
||||||
# links_user_id_section_id_position (user_id,sidebar_section_id,position) UNIQUE
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddSidebarSectionIdIndexToSidebarSectionLink < ActiveRecord::Migration[7.0]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def up
|
||||||
|
execute <<~SQL
|
||||||
|
DROP INDEX CONCURRENTLY IF EXISTS idx_sidebar_section_links_on_sidebar_section_id
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<~SQL
|
||||||
|
CREATE UNIQUE INDEX CONCURRENTLY idx_sidebar_section_links_on_sidebar_section_id
|
||||||
|
ON sidebar_section_links (sidebar_section_id, user_id, position)
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<~SQL
|
||||||
|
DROP INDEX CONCURRENTLY IF EXISTS links_user_id_section_id_position
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
execute <<~SQL
|
||||||
|
DROP INDEX CONCURRENTLY IF EXISTS idx_sidebar_section_links_on_sidebar_section_id
|
||||||
|
SQL
|
||||||
|
|
||||||
|
add_index :sidebar_section_links,
|
||||||
|
%i[user_id sidebar_section_id position],
|
||||||
|
unique: true,
|
||||||
|
name: "links_user_id_section_id_position"
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user