mirror of
https://github.com/discourse/discourse.git
synced 2025-02-27 18:49:41 +08:00
PERF: deleting a post in huge topics was timing out
- add missing index to user actions for fast retrieval by post - add missing indexes to users for fast retrieval of staff - only refresh topic_users liked/bookmarked cache for affected users
This commit is contained in:
parent
9cdfef2b27
commit
1343d40558
@ -232,6 +232,7 @@ class TopicUser < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.update_post_action_cache(opts={})
|
def self.update_post_action_cache(opts={})
|
||||||
user_id = opts[:user_id]
|
user_id = opts[:user_id]
|
||||||
|
post_id = opts[:post_id]
|
||||||
topic_id = opts[:topic_id]
|
topic_id = opts[:topic_id]
|
||||||
action_type = opts[:post_action_type]
|
action_type = opts[:post_action_type]
|
||||||
|
|
||||||
@ -277,6 +278,13 @@ SQL
|
|||||||
builder.where("tu2.topic_id = :topic_id", topic_id: topic_id)
|
builder.where("tu2.topic_id = :topic_id", topic_id: topic_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if post_id
|
||||||
|
builder.where("tu2.topic_id IN (SELECT topic_id FROM posts WHERE id = :post_id)", post_id: post_id)
|
||||||
|
builder.where("tu2.user_id IN (SELECT user_id FROM post_actions
|
||||||
|
WHERE post_id = :post_id AND
|
||||||
|
post_action_type_id = :action_type_id)")
|
||||||
|
end
|
||||||
|
|
||||||
builder.exec(action_type_id: PostActionType.types[action_type])
|
builder.exec(action_type_id: PostActionType.types[action_type])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
class AddIndexTargetPostIdOnUserActions < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_index :user_actions, [:target_post_id]
|
||||||
|
end
|
||||||
|
end
|
6
db/migrate/20150617234511_add_staff_index_to_users.rb
Normal file
6
db/migrate/20150617234511_add_staff_index_to_users.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class AddStaffIndexToUsers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_index :users, [:id], name: 'idx_users_admin', where: 'admin'
|
||||||
|
add_index :users, [:id], name: 'idx_users_moderator', where: 'moderator'
|
||||||
|
end
|
||||||
|
end
|
@ -90,7 +90,7 @@ class PostDestroyer
|
|||||||
end
|
end
|
||||||
update_associated_category_latest_topic
|
update_associated_category_latest_topic
|
||||||
update_user_counts
|
update_user_counts
|
||||||
TopicUser.update_post_action_cache(topic_id: @post.topic_id)
|
TopicUser.update_post_action_cache(post_id: @post.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature_users_in_the_topic if @post.topic
|
feature_users_in_the_topic if @post.topic
|
||||||
|
Loading…
x
Reference in New Issue
Block a user