Skip to content

Commit

Permalink
resolve cc issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DGaffney committed Mar 21, 2024
1 parent 83712d8 commit 68072c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions app/models/concerns/alegre_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def safe_get_sync(project_media, field, params={})
def cache_items_via_callback(project_media, field, confirmed, results)
relationship_type = confirmed ? Relationship.confirmed_type : Relationship.suggested_type
type = Bot::Alegre.get_type(project_media)
threshold = Bot::Alegre.get_per_model_threshold(project_media, Bot::Alegre.get_threshold_for_query(type, project_media, confirmed))
Bot::Alegre.parse_similarity_results(
project_media,
field,
Expand Down Expand Up @@ -327,10 +326,10 @@ def get_required_keys(project_media, field)
suggested_or_confirmed_results: "alegre:async_results:#{project_media.id}_#{field}_false"
}
end

def get_cached_data(required_keys)
redis = Redis.new(REDIS_CONFIG)
Hash[required_keys.collect{|k,v| [k, (Hash[JSON.parse(redis.get(v)).collect{|k,v| [k.to_i, v]}] rescue [])]}]
Hash[required_keys.collect{|k,v| [k, (Hash[JSON.parse(redis.get(v)).collect{|kk,vv| [kk.to_i, vv]}] rescue [])]}]
end

def get_similar_items_v2_callback(project_media, field)
Expand Down
11 changes: 5 additions & 6 deletions app/models/concerns/alegre_webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ def valid_request?(request)

def webhook(request)
begin
params = request.params
puts request.inspect
doc_id = params.dig('data', 'requested', 'id')
doc_id = params.dig('data', 'item', 'id') if doc_id.nil?
is_from_alegre_callback = params.dig('data', 'item', 'callback_url').to_s.include?("/presto/receive/add_item")
doc_id = request.params.dig('data', 'requested', 'id')
doc_id = request.params.dig('data', 'item', 'id') if doc_id.nil?
is_from_alegre_callback = request.params.dig('data', 'item', 'callback_url').to_s.include?("/presto/receive/add_item")
raise 'Unexpected params format' if doc_id.blank?
if is_from_alegre_callback
Bot::Alegre.process_alegre_callback(params)
Bot::Alegre.process_alegre_callback(request.params)
else
redis = Redis.new(REDIS_CONFIG)
key = "alegre:webhook:#{doc_id}"
Expand All @@ -31,4 +30,4 @@ def webhook(request)
end
end
end
end
end

0 comments on commit 68072c5

Please sign in to comment.