mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: add index to sidebar_section_link (#20234)
Index on linkable_type and linkable_id should increase performance of this subquery https://github.com/discourse/discourse/blob/main/app/services/sidebar_site_settings_backfiller.rb#L86 Also, distinct is removing duplicates which are unnecessary.
This commit is contained in:
parent
6338287e89
commit
cbd021db15
@ -40,5 +40,6 @@ end
|
|||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
# 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)
|
||||||
#
|
#
|
||||||
|
@ -81,7 +81,7 @@ class SidebarSiteSettingsBackfiller
|
|||||||
FROM users
|
FROM users
|
||||||
WHERE users.id NOT IN (
|
WHERE users.id NOT IN (
|
||||||
SELECT
|
SELECT
|
||||||
sidebar_section_links.user_id
|
DISTINCT(sidebar_section_links.user_id)
|
||||||
FROM sidebar_section_links
|
FROM sidebar_section_links
|
||||||
WHERE sidebar_section_links.linkable_type = '#{@linkable_klass.to_s}'
|
WHERE sidebar_section_links.linkable_type = '#{@linkable_klass.to_s}'
|
||||||
AND sidebar_section_links.linkable_id IN (#{@added_ids.join(",")})
|
AND sidebar_section_links.linkable_id IN (#{@added_ids.join(",")})
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddLinkableIndexToSidebarSectionLinks < ActiveRecord::Migration[7.0]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def up
|
||||||
|
execute <<~SQL
|
||||||
|
DROP INDEX CONCURRENTLY IF EXISTS index_sidebar_section_links_on_linkable_type_and_linkable_id
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<~SQL
|
||||||
|
CREATE INDEX CONCURRENTLY index_sidebar_section_links_on_linkable_type_and_linkable_id
|
||||||
|
ON sidebar_section_links (linkable_type,linkable_id)
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
execute <<~SQL
|
||||||
|
DROP INDEX CONCURRENTLY IF EXISTS index_sidebar_section_links_on_linkable_type_and_linkable_id
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user