FIX: Regression with finding reviewable counts on topics

FIX: Regression with finding reviewable counts on topics

This was a fairly serious regression on sites with large (mega) topics, however it was limited to staff.

The issue here is the query was using filtered_post_ids which I’d assumed was already windowed to the current page, when in fact it was all the ids in the topic. This fix corrects it by using the correct windowed collection.

diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index e9b1250..57b7585 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -424,7 +424,7 @@ class TopicView
       # Create a hash with counts by post so we can quickly look up whether there is reviewable content.
       @reviewable_counts = {}
       Reviewable.
-        where(target_type: 'Post', target_id: filtered_post_ids).
+        where(target_type: 'Post', target_id: @posts.map(&:id)).
         includes(:reviewable_scores).each do |r|
 
         for_post = (@reviewable_counts[r.target_id] ||= { total: 0, pending: 0, reviewable_id: r.id })

GitHub sha: f86a5bd5

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: