A platform for community discussion. Free, open, simple.
PERF: add a filtered index for banners
Sam Saffron70c6831125e3
diff --git a/app/models/draft.rb b/app/models/draft.rbindex 610b8ef26dc..2bbc3bcaf66 100644--- a/app/models/draft.rb+++ b/app/models/draft.rb@@ -278,6 +278,7 @@ end# updated_at :datetime not null# sequence :integer default(0), not null# revisions :integer default(1), not null+# owner :string## Indexes#diff --git a/app/models/topic.rb b/app/models/topic.rbindex 85cff4f7e3b..1af8598d2d2 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -1544,6 +1544,7 @@ end# index_topics_on_bumped_at (bumped_at)# index_topics_on_created_at_and_visible (created_at,visible) WHERE ((deleted_at IS NULL) AND ((archetype)::text <> 'private_message'::text))# index_topics_on_id_and_deleted_at (id,deleted_at)+# index_topics_on_id_filtered_banner (id) UNIQUE WHERE (((archetype)::text = 'banner'::text) AND (deleted_at IS NULL))# index_topics_on_lower_title (lower((title)::text))# index_topics_on_pinned_at (pinned_at) WHERE (pinned_at IS NOT NULL)# index_topics_on_pinned_globally (pinned_globally) WHERE pinned_globallydiff --git a/db/migrate/20191101001705_add_banner_index_to_topics.rb b/db/migrate/20191101001705_add_banner_index_to_topics.rbnew file mode 100644index 00000000000..ecafad00dec--- /dev/null+++ b/db/migrate/20191101001705_add_banner_index_to_topics.rb@@ -0,0 +1,7 @@+# frozen_string_literal: true+class AddBannerIndexToTopics < ActiveRecord::Migration[6.0]+ def change+ # this speeds up the process for finding banners on the site+ add_index :topics, [:id], name: 'index_topics_on_id_filtered_banner', where: "archetype = 'banner' AND deleted_at IS NULL", unique: true+ end+end