PERF: slow user pages in admin. add an index for trust level 3 calculations, and memoize query results
This commit is contained in:
parent
7412ff4da7
commit
4c0129ccdd
|
@ -134,12 +134,12 @@ class TrustLevel3Requirements
|
|||
end
|
||||
|
||||
def num_flagged_by_users
|
||||
PostAction.with_deleted
|
||||
.where(post_id: flagged_post_ids)
|
||||
.where.not(user_id: @user.id)
|
||||
.where.not(agreed_at: nil)
|
||||
.pluck(:user_id)
|
||||
.uniq.count
|
||||
@_num_flagged_by_users ||= PostAction.with_deleted
|
||||
.where(post_id: flagged_post_ids)
|
||||
.where.not(user_id: @user.id)
|
||||
.where.not(agreed_at: nil)
|
||||
.pluck(:user_id)
|
||||
.uniq.count
|
||||
end
|
||||
|
||||
def max_flagged_by_users
|
||||
|
@ -212,9 +212,9 @@ class TrustLevel3Requirements
|
|||
end
|
||||
|
||||
def flagged_post_ids
|
||||
@user.posts
|
||||
.with_deleted
|
||||
.where('created_at > ? AND (spam_count > 0 OR inappropriate_count > 0)', TIME_PERIOD.days.ago)
|
||||
.pluck(:id)
|
||||
@_flagged_post_ids ||= @user.posts
|
||||
.with_deleted
|
||||
.where('created_at > ? AND (spam_count > 0 OR inappropriate_count > 0)', TIME_PERIOD.days.ago)
|
||||
.pluck(:id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddPostsIndexIncludingDeleted < ActiveRecord::Migration
|
||||
def change
|
||||
add_index :posts, [:user_id, :created_at]
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue