From a475c384d8c8ddfecfca121fb6ac2050ff7d7aa6 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 6 Aug 2019 15:02:45 +0200 Subject: [PATCH] FIX: ensures flag-ratio report shows users with disagreed > agreed (#7977) Without causing a division by zero error --- app/models/reports/user_flagging_ratio.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/reports/user_flagging_ratio.rb b/app/models/reports/user_flagging_ratio.rb index 403304e9efd..f6a5fb53c5f 100644 --- a/app/models/reports/user_flagging_ratio.rb +++ b/app/models/reports/user_flagging_ratio.rb @@ -53,7 +53,10 @@ Report.add_report("user_flagging_ratio") do |report| #{disagreed} AS disagreed_flags, #{agreed} AS agreed_flags, #{ignored} AS ignored_flags, - ROUND((1-(#{agreed} / #{disagreed})) * (#{disagreed} - #{agreed})) AS score + ( + CASE #{disagreed} WHEN 0 THEN #{agreed} * #{agreed} + ELSE ROUND((1-(#{agreed} / #{disagreed})) * (#{disagreed} - #{agreed})) END + ) AS score FROM users AS u INNER JOIN reviewable_scores AS rs ON rs.user_id = u.id WHERE u.id > 0 @@ -63,7 +66,6 @@ Report.add_report("user_flagging_ratio") do |report| u.username, u.uploaded_avatar_id, u.silenced_till - HAVING #{disagreed} > #{agreed} ORDER BY score DESC LIMIT 100 SQL