Skip to content

Commit

Permalink
Fixing Sentry error and avoiding race condition
Browse files Browse the repository at this point in the history
This PR fixes two things:

* A Sentry error that was raised when a report is null
* A race condition that happens when saving media related to tipline search results

Reference: CV2-4063.
  • Loading branch information
caiosba committed Nov 30, 2023
1 parent 4fd7fb9 commit 5d219b7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/models/concerns/smooch_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def handle_bundle_messages(type, list, last, app_id, annotated, send_message = t
if ['timeout_requests', 'menu_options_requests', 'resource_requests', 'relevant_search_result_requests', 'timeout_search_requests'].include?(type)
key = "smooch:banned:#{bundle['authorId']}"
if Rails.cache.read(key).nil?
[annotated].flatten.uniq.each_with_index { |a, i| self.save_message_later(bundle, app_id, type, a, i * 10) }
[annotated].flatten.uniq.each_with_index { |a, i| self.save_message_later(bundle, app_id, type, a, i * 60) }
end
end
end
Expand Down Expand Up @@ -320,7 +320,7 @@ def supported_message?(message)
def save_message_later(message, app_id, request_type = 'default_requests', annotated = nil, interval = 0)
mapping = { 'siege' => 'siege' }
queue = RequestStore.store[:smooch_bot_queue].to_s
queue = queue.blank? ? 'smooch' : (mapping[queue] || 'smooch')
queue = queue.blank? ? 'smooch_priority' : (mapping[queue] || 'smooch_priority')
type = (message['type'] == 'text' && !message['text'][/https?:\/\/[^\s]+/, 0].blank?) ? 'link' : message['type']
SmoochWorker.set(queue: queue).perform_in(1.second + interval.seconds, message.to_json, type, app_id, request_type, YAML.dump(annotated))
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/smooch_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ def send_search_results_to_user(uid, results, team_id)
language = self.get_user_language(uid)
reports = results.collect{ |r| r.get_dynamic_annotation('report_design') }
# Get reports languages
reports_language = reports.map{|r| r&.report_design_field_value('language')}.uniq
reports_language = reports.map { |r| r&.report_design_field_value('language') }.uniq
if team.get_languages.to_a.size > 1 && !reports_language.include?(language)
self.send_message_to_user(uid, self.get_string(:no_results_in_language, language).gsub('%{language}', CheckCldr.language_code_to_name(language, language)), {}, false, true, 'no_results')
sleep 1
end
reports.each do |report|
reports.reject{ |r| r.blank? }.each do |report|
response = nil
response = self.send_message_to_user(uid, report.report_design_text, {}, false, true, 'search_result') if report.report_design_field_value('use_text_message')
response = self.send_message_to_user(uid, '', { 'type' => 'image', 'mediaUrl' => report.report_design_image_url }, false, true, 'search_result') if !report.report_design_field_value('use_text_message') && report.report_design_field_value('use_visual_card')
Expand Down

0 comments on commit 5d219b7

Please sign in to comment.