diff --git a/app/models/trust_level3_requirements.rb b/app/models/trust_level3_requirements.rb index a42775e123d..919db83174c 100644 --- a/app/models/trust_level3_requirements.rb +++ b/app/models/trust_level3_requirements.rb @@ -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 diff --git a/db/migrate/20150119192813_add_posts_index_including_deleted.rb b/db/migrate/20150119192813_add_posts_index_including_deleted.rb new file mode 100644 index 00000000000..20d6e588df3 --- /dev/null +++ b/db/migrate/20150119192813_add_posts_index_including_deleted.rb @@ -0,0 +1,5 @@ +class AddPostsIndexIncludingDeleted < ActiveRecord::Migration + def change + add_index :posts, [:user_id, :created_at] + end +end