mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
PERF: Perform only one category update when creating a new topic (#19361)
When under extremely high load, it has been observed that updating the categories table when creating a new topic can become a bottleneck. This change will reduce the two updates to one when a new topic is created within a category, and therefore should help with performance when under extremely high load.
This commit is contained in:
parent
16e3bc3ff4
commit
64b781dacf
@ -425,8 +425,11 @@ class PostCreator
|
||||
def track_latest_on_category
|
||||
return unless @post && @post.errors.count == 0 && @topic && @topic.category_id
|
||||
|
||||
Category.where(id: @topic.category_id).update_all(latest_post_id: @post.id)
|
||||
Category.where(id: @topic.category_id).update_all(latest_topic_id: @topic.id) if @post.is_first_post?
|
||||
if @post.is_first_post?
|
||||
Category.where(id: @topic.category_id).update_all(latest_topic_id: @topic.id, latest_post_id: @post.id)
|
||||
else
|
||||
Category.where(id: @topic.category_id).update_all(latest_post_id: @post.id)
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_in_allowed_users
|
||||
|
Loading…
Reference in New Issue
Block a user