FIX: correctly count assigned topics for user

approved
#1

FIX: correctly count assigned topics for user

Previously we were looking at deleted topics

diff --git a/lib/topic_assigner.rb b/lib/topic_assigner.rb
index 8cfb2e9..181212a 100644
--- a/lib/topic_assigner.rb
+++ b/lib/topic_assigner.rb
@@ -134,11 +134,11 @@ SQL
     return true if @assigned_by.id == user.id
 
     assigned_total = TopicCustomField
-      .where('name = ? OR name = ?', ASSIGNED_TO_ID, ASSIGNED_BY_ID)
+      .joins(:topic)
+      .where(topics: { deleted_at: nil })
+      .where(name: ASSIGNED_TO_ID)
       .where(value: user.id)
-      .group(:topic_id)
-      .having('COUNT(*) = 1')
-      .count.length
+      .count
 
     assigned_total < SiteSetting.max_assigned_topics
   end

GitHub sha: 6f031f54

1 Like
Approved #2