Skip to content

Commit

Permalink
Delete old tipline request and fix sentry issue (#1817)
Browse files Browse the repository at this point in the history
* CV2-4351: fix sentry issue

* CV2-4352: delete old tipline requests(annotation of type smooch)

* CV2-4352: add logs to rake task
  • Loading branch information
melsawy authored and caiosba committed Mar 5, 2024
1 parent d5787ba commit a34df53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/concerns/team_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def text_contains_keyword(text, value)

def get_smooch_message(pm)
smooch_message = pm.smooch_message
smooch_message.nil? ? pm.tipline_requests.last.smooch_data : smooch_message
smooch_message.nil? ? pm.tipline_requests.last&.smooch_data : smooch_message
end

def title_matches_regexp(pm, value, _rule_id)
Expand Down
17 changes: 17 additions & 0 deletions lib/tasks/migrate/20231122054128_migrate_tipline_requests.rake
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,22 @@ namespace :check do
minutes = ((Time.now.to_i - started) / 60).to_i
puts "[#{Time.now}] Done in #{minutes} minutes."
end

# Remove old tipline requests (annotations of type smooch)
# bundle exec rails check:migrate:remove_old_tipline_requests
task remove_old_tipline_requests: :environment do
started = Time.now.to_i
total = Annotation.where(annotation_type: 'smooch').count
deleted = 0
Annotation.where(annotation_type: 'smooch').find_in_batches(:batch_size => 2000) do |annotations|
ids = annotations.map(&:id)
deleted += ids.count
DynamicAnnotation::Field.where(annotation_type: 'smooch', annotation_id: ids).delete_all
Annotation.where(id: ids).delete_all
puts "\nDeleted #{deleted} / #{total}\n"
end
minutes = ((Time.now.to_i - started) / 60).to_i
puts "[#{Time.now}] Done in #{minutes} minutes."
end
end
end

0 comments on commit a34df53

Please sign in to comment.