Skip to content

Commit

Permalink
add response suppression and move to specific path for side effecting…
Browse files Browse the repository at this point in the history
… requests
  • Loading branch information
DGaffney committed Aug 19, 2024
1 parent 6e6e68f commit a9576ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/models/concerns/alegre_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ def store_package_text(project_media, field, params)
generic_package_text(project_media, field, params)
end

def index_async_with_params(params, type, suppress_response=true)
request("post", async_path_for_type(type), params.merge(suppress_response: suppress_response))
end

def get_sync_with_params(params, type)
request("post", sync_path_for_type(type), params)
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/explainer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def self.update_paragraphs_in_alegre(id, previous_paragraphs_count, timestamp)
text: explainer.title,
models: ALEGRE_MODELS_AND_THRESHOLDS.keys,
}
Bot::Alegre.get_sync_with_params(params, "text")
Bot::Alegre.index_async_with_params(params, "text")

# Index paragraphs
count = 0
Expand All @@ -82,7 +82,7 @@ def self.update_paragraphs_in_alegre(id, previous_paragraphs_count, timestamp)
text: paragraph.strip,
models: ALEGRE_MODELS_AND_THRESHOLDS.keys,
}
Bot::Alegre.get_sync_with_params(params, "text")
Bot::Alegre.index_async_with_params(params, "text")
end

# Remove paragraphs that don't exist anymore (we delete after updating in order to avoid race conditions)
Expand All @@ -108,7 +108,7 @@ def self.search_by_similarity(text, language, team_id)
language: language
}
}
response = Bot::Alegre.get_sync_with_params(params, "text")
response = Bot::Alegre.index_async_with_params(params, "text")
results = response['result'].to_a.sort_by{ |result| result['_score'] }
explainer_ids = results.collect{ |result| result.dig('_source', 'context', 'explainer_id').to_i }.uniq.first(3)
explainer_ids.empty? ? Explainer.none : Explainer.where(team_id: team_id, id: explainer_ids)
Expand Down

0 comments on commit a9576ba

Please sign in to comment.