mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08: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
@ -1357,11 +1357,11 @@ class Topic < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def public_topic_timer
|
||||
@public_topic_timer ||= topic_timers.find_by(deleted_at: nil, public_type: true)
|
||||
@public_topic_timer ||= topic_timers.find_by(public_type: true)
|
||||
end
|
||||
|
||||
def slow_mode_topic_timer
|
||||
@slow_mode_topic_timer ||= topic_timers.find_by(deleted_at: nil, status_type: TopicTimer.types[:clear_slow_mode])
|
||||
@slow_mode_topic_timer ||= topic_timers.find_by(status_type: TopicTimer.types[:clear_slow_mode])
|
||||
end
|
||||
|
||||
def delete_topic_timer(status_type, by_user: Discourse.system_user)
|
||||
|
Reference in New Issue
Block a user