Skip to content

Commit

Permalink
[Issue #1835] Remove distinct from inner query of search (#1836)
Browse files Browse the repository at this point in the history
## Summary
Fixes #1835

### Time to review: __3 mins__

## Changes proposed
Adjust the search query to not do `distinct` on the inner filter query

## Context for reviewers

This distinct originally was added as the query was setup in a much
different way. We needed to do the distinct to avoid duplicates when
doing joins, but because it is now an inner query - quite literally used
as `select ... where opportunity_id in (select distinct opportunity_id
...)` we don't need to distinct it. If the values aren't distinct, it
doesn't actually change the outer query, there will just be dupes in
that list, but that's fine and seems to be better performing.
  • Loading branch information
chouinar authored Apr 25, 2024
1 parent 043ed8c commit 960cdd6
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions api/src/services/opportunities_v0_1/search_opportunities.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def search_opportunities(
a set of opportunity IDs for the outer query to filter against. This query
ends up looking like (varying based on exact filters):
SELECT DISTINCT
SELECT
opportunity.opportunity_id
FROM opportunity
JOIN current_opportunity_summary ON opportunity.opportunity_id = current_opportunity_summary.opportunity_id
Expand All @@ -220,9 +220,6 @@ def search_opportunities(
) # Only ever return non-drafts
# Filter anything without a current opportunity summary
.where(Opportunity.current_opportunity_summary != None) # noqa: E711
# Distinct the opportunity IDs returned so that the outer query
# has fewer results to query against
.distinct()
)

# Current + Opportunity Summary are always needed so just add them here
Expand Down

0 comments on commit 960cdd6

Please sign in to comment.