add stream item clearing to job if production

This was causing problems when there were too many stream item instances
that needed to be dealt with inside the transaction.

fixes LA-923
fixes LA-922
flag=none

Change-Id: Idccffb6206aaa3c8a28dd7b1be713018a5ee388e
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/234220
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: James Williams <jamesw@instructure.com>
Reviewed-by: Rob Orton <rob@instructure.com>
QA-Review: Rob Orton <rob@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Matthew Lemon 2020-04-15 13:10:10 -06:00
parent 7ede798549
commit 35c4386844
1 changed files with 13 additions and 5 deletions

View File

@ -929,6 +929,10 @@ class DiscussionTopic < ActiveRecord::Base
# either changed sections or made section specificness
return unless self.is_section_specific? ? @sections_changed : self.is_section_specific_before_last_save
send_later_if_production(:clear_stream_items_for_sections)
end
def clear_stream_items_for_sections
remaining_participants = participants
user_ids = []
stream_item&.stream_item_instances&.find_each do |item|
@ -942,12 +946,16 @@ class DiscussionTopic < ActiveRecord::Base
end
def clear_non_applicable_stream_items_for_delayed_posts
user_ids = []
if self.is_announcement && self.delayed_post_at? && @delayed_post_at_changed && self.delayed_post_at > Time.now
stream_item&.stream_item_instances&.find_each do |item|
user_ids.push(item.user_id)
item.destroy
end
send_later_if_production(:clear_stream_items_for_delayed_posts)
end
end
def clear_stream_items_for_delayed_posts
user_ids = []
stream_item&.stream_item_instances&.find_each do |item|
user_ids.push(item.user_id)
item.destroy
end
self.clear_stream_item_cache_for(user_ids)
end