mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 17:15:25 +08: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
|
def track_latest_on_category
|
||||||
return unless @post && @post.errors.count == 0 && @topic && @topic.category_id
|
return unless @post && @post.errors.count == 0 && @topic && @topic.category_id
|
||||||
|
|
||||||
|
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)
|
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?
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_in_allowed_users
|
def ensure_in_allowed_users
|
||||||
|
|
Loading…
Reference in New Issue
Block a user