Skip to content

Commit

Permalink
Change order of data retrieval for faster query
Browse files Browse the repository at this point in the history
  • Loading branch information
achan authored and achan committed Dec 30, 2024
1 parent aae3784 commit 1a81d6f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/controllers/v1/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ def location
def program
@query ||= normalized_query_params

# Start with filtering by institution programs based on description
institution_programs = InstitutionProgram.joins(:institution)
.where('institution_programs.description ILIKE ?', "%#{@query[:description]}%")
.where(institutions: { version: @version })

# Now filter by location
# Start with fast location search
location_results = Institution.approved_institutions(@version)
.location_search(@query)
.filter_result_v1(@query)
.where(id: institution_programs.select(:institution_id))

results = location_results.location_select(@query).location_order
# Then filter those results by program description
results = location_results
.joins(:institution_programs)
.where('institution_programs.description ILIKE ?', "%#{@query[:description]}%")
.location_select(@query)
.location_order

results = results.filter_high_school if @query[:excluded_school_types]&.include?('HIGH SCHOOL')

@meta = {
version: @version,
count: location_results.count,
count: results.unscope(:select).count, # Add unscope
facets: facets(location_results)
}

Expand Down

0 comments on commit 1a81d6f

Please sign in to comment.