Skip to content

Commit

Permalink
Stop storing search results as suggestins
Browse files Browse the repository at this point in the history
During our attempt to get user feedback, we created a new workflow
to log all returned content as suggestions. This creates unnecessary
work for Check users.
  • Loading branch information
jayjay-w committed Feb 12, 2024
1 parent 75de8b1 commit 6b4bf7f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
3 changes: 0 additions & 3 deletions app/models/concerns/smooch_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,6 @@ def save_message(message_json, app_id, author = nil, request_type = 'default_req
elsif ['relevant_search_result_requests', 'timeout_search_requests'].include?(request_type)
message['archived'] = (request_type == 'relevant_search_result_requests' ? self.default_archived_flag : CheckArchivedFlags::FlagCodes::UNCONFIRMED)
associated = self.create_project_media_from_message(message)
if associated != associated_obj && associated.is_a?(ProjectMedia)
Relationship.create(relationship_type: Relationship.suggested_type, source: associated_obj, target: associated, user: BotUser.smooch_user)
end
end

return if associated.nil?
Expand Down
9 changes: 0 additions & 9 deletions app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Relationship < ApplicationRecord
validates :relationship_type, uniqueness: { scope: [:source_id, :target_id], message: :already_exists }, on: :create

before_create :destroy_same_suggested_item, if: proc { |r| r.is_confirmed? }
before_update :destroy_other_suggested_items, if: proc { |r| r.is_confirmed? }
after_create :move_to_same_project_as_main, prepend: true
after_create :point_targets_to_new_source, :update_counters, prepend: true
after_update :reset_counters, prepend: true
Expand Down Expand Up @@ -315,14 +314,6 @@ def destroy_same_suggested_item
.destroy_all
end

def destroy_other_suggested_items
# If created by Smooch Bot, destroy other suggestions to the same media
Relationship.where(target_id: self.target_id, user: BotUser.smooch_user)
.where('relationship_type = ?', Relationship.suggested_type.to_yaml)
.where('id != ?', self.id)
.destroy_all
end

def cant_be_related_to_itself
errors.add(:base, I18n.t(:item_cant_be_related_to_itself)) if self.source_id == self.target_id
end
Expand Down
12 changes: 4 additions & 8 deletions test/models/bot/smooch_6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def send_message_outside_24_hours_window(template, pm = nil)
Sidekiq::Testing.inline! do
send_message 'hello', '1', '1', 'Foo bar', '1'
assert_state 'search_result'
assert_difference 'TiplineRequest.count + ProjectMedia.count + Relationship.where(relationship_type: Relationship.suggested_type).count', 3 do
assert_difference 'TiplineRequest.count + ProjectMedia.count', 2 do
send_message '1'
end
assert_state 'main'
Expand All @@ -240,7 +240,7 @@ def send_message_outside_24_hours_window(template, pm = nil)
Sidekiq::Testing.inline! do
send_message 'hello', '1', '1', 'Foo bar foo bar foo bar', '1'
assert_state 'search_result'
assert_difference 'TiplineRequest.count + ProjectMedia.count + Relationship.where(relationship_type: Relationship.suggested_type).count', 3 do
assert_difference 'TiplineRequest.count + ProjectMedia.count', 2 do
send_message '1'
end
assert_state 'main'
Expand All @@ -262,12 +262,8 @@ def send_message_outside_24_hours_window(template, pm = nil)
Sidekiq::Testing.inline! do
send_message 'hello', '1', '1', 'Image here', '1'
assert_state 'search_result'
assert_difference 'TiplineRequest.count' do
assert_difference 'ProjectMedia.count' do
assert_difference 'Relationship.where(relationship_type: Relationship.suggested_type).count' do
send_message '1'
end
end
assert_difference 'TiplineRequest.count + ProjectMedia.count', 2 do
send_message '1'
end
assert_state 'main'
end
Expand Down

0 comments on commit 6b4bf7f

Please sign in to comment.