diff --git a/app/logical/moderator/dashboard/queries/tag.rb b/app/logical/moderator/dashboard/queries/tag.rb index a3411bbdb..72999326a 100644 --- a/app/logical/moderator/dashboard/queries/tag.rb +++ b/app/logical/moderator/dashboard/queries/tag.rb @@ -5,26 +5,17 @@ module Moderator attr_reader :user, :count def self.all(min_date, max_level) - sql = <<-EOS - SELECT post_versions.updater_id, count(*) - FROM post_versions - JOIN users ON users.id = post_versions.updater_id - WHERE - post_versions.updated_at > ? - AND users.level <= ? - GROUP BY post_versions.updater_id - ORDER BY count(*) DESC - LIMIT 10 - EOS + return unless PostArchive.enabled? - ActiveRecord::Base.without_timeout do - ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)} + records = PostArchive.where("updated_at > ?", min_date).group(:updater).count.map do |user, count| + new(user, count) end + + records.select { |rec| rec.user.level <= max_level }.sort_by(&:count).reverse.take(10) end - def initialize(hash) - @user = ::User.find(hash["updater_id"]) - @count = hash["count"] + def initialize(user, count) + @user, @count = user, count end end end diff --git a/app/logical/moderator/dashboard/report.rb b/app/logical/moderator/dashboard/report.rb index c3600e8ac..39ce34f8b 100644 --- a/app/logical/moderator/dashboard/report.rb +++ b/app/logical/moderator/dashboard/report.rb @@ -45,9 +45,7 @@ module Moderator end def tags - ActiveRecord::Base.without_timeout do - Queries::Tag.all(min_date, max_level) - end + Queries::Tag.all(min_date, max_level) end def posts