mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Add index for TopicTimer#topic_id (#17680)
When viewing a topic, we execute two queries to fetch the topic's public topic timer and slow mode timer. The former query happens to be able to use a unique index but the latter has to do a seq scan which is slow. The query itself is not expensive but since viewing a topic is a hot path, the little cuts add up overtime and the query itself contributes significantly to the load of the database.
This commit is contained in:
committed by
GitHub
parent
3682513475
commit
dcf84fce7b
7
db/migrate/20220727040437_add_topic_timers_index.rb
Normal file
7
db/migrate/20220727040437_add_topic_timers_index.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddTopicTimersIndex < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_index :topic_timers, [:topic_id], where: "deleted_at IS NULL"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user