Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop storing search results as suggestions #1797

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading