avoid raw SQL in attachment notifier
refs CNVS-26480 Change-Id: I6c668b9c1b3f5b344b481c1fcb8001c8e48aa783 Reviewed-on: https://gerrit.instructure.com/71833 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
f097649377
commit
51e5d1dbdd
|
@ -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)<?", quiet_period).
|
||||
limit(500).
|
||||
pluck("COUNT(attachments.id), MIN(attachments.id), MAX(updated_at), context_id, context_type")
|
||||
break if file_batches.empty?
|
||||
file_batches.each do |count, attachment_id, last_updated_at, context_id, context_type|
|
||||
# clear the need_notify flag for this batch
|
||||
|
|
Loading…
Reference in New Issue