Skip to content

Commit

Permalink
Removing threads
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosba committed Jan 28, 2025
1 parent bee0063 commit 118c5cd
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -573,29 +573,23 @@ def search_for_similar_articles(query, pm = nil, language = nil, settings = nil)
# query: expected to be text
# pm: to request a most relevant to specific item and also include both FactCheck & Explainer
limit = self.similar_articles_search_limit(pm)
threads = []
fc_items = []
ex_items = []
threads << Thread.new {
result_ids = Bot::Smooch.search_for_similar_published_fact_checks_no_cache('text', query, [self.id], limit, nil, nil, language, false, settings).map(&:id)
unless result_ids.blank?
fc_items = FactCheck.joins(claim_description: :project_media).where('project_medias.id': result_ids)
if pm.nil?
# This means we obtain relevant items for the Bot preview, so we should limit FactChecks to published articles;
# otherwise, relevant articles for ProjectMedia should include all FactChecks.
fc_items = fc_items.where(report_status: 'published')
elsif !pm.fact_check_id.nil?
# Exclude the ones already applied to a target item if exists.
fc_items = fc_items.where.not('fact_checks.id' => pm.fact_check_id) unless pm&.fact_check_id.nil?
end
result_ids = Bot::Smooch.search_for_similar_published_fact_checks_no_cache('text', query, [self.id], limit, nil, nil, language, false, settings).map(&:id)
unless result_ids.blank?
fc_items = FactCheck.joins(claim_description: :project_media).where('project_medias.id': result_ids)
if pm.nil?
# This means we obtain relevant items for the Bot preview, so we should limit FactChecks to published articles;
# otherwise, relevant articles for ProjectMedia should include all FactChecks.
fc_items = fc_items.where(report_status: 'published')
elsif !pm.fact_check_id.nil?
# Exclude the ones already applied to a target item if exists.
fc_items = fc_items.where.not('fact_checks.id' => pm.fact_check_id) unless pm&.fact_check_id.nil?
end
}
threads << Thread.new {
ex_items = Bot::Smooch.search_for_explainers(nil, query, self.id, limit, language, settings).distinct
# Exclude the ones already applied to a target item
ex_items = ex_items.where.not(id: pm.explainer_ids) unless pm&.explainer_ids.blank?
}
threads.map(&:join)
end
ex_items = Bot::Smooch.search_for_explainers(nil, query, self.id, limit, language, settings).distinct
# Exclude the ones already applied to a target item
ex_items = ex_items.where.not(id: pm.explainer_ids) unless pm&.explainer_ids.blank?
items = fc_items
# Get Explainers if no fact-check returned or get similar_articles for a ProjectMedia
items += ex_items if items.blank? || !pm.nil?
Expand Down

0 comments on commit 118c5cd

Please sign in to comment.