diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 3af4289053c..95a4771fea1 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -787,10 +787,12 @@ class Attachment < ActiveRecord::Base discard_older_than = Setting.get("attachment_notify_discard_older_than_hours", "120").to_i.hours.ago while true - file_batches = Attachment.connection.select_rows(sanitize_sql([<<-SQL, quiet_period])) - SELECT COUNT(attachments.id), MIN(attachments.id), MAX(updated_at), context_id, context_type - FROM attachments WHERE need_notify GROUP BY context_id, context_type HAVING MAX(updated_at) < ? LIMIT 500 - SQL + file_batches = Attachment. + where("need_notify"). + group(:context_id, :context_type). + having("MAX(updated_at)