Skip to content

Commit

Permalink
optimize search when no filters are provided
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeBu committed Oct 3, 2024
1 parent 4c0b610 commit 5bef8b7
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,23 @@ const searchImmersionResultsQuery = (
return qb.whereRef("searchable_by_students", "is", sql`TRUE`);
return qb;
},
(qb) => {
if (
!filters?.geoParams &&
!filters?.romeCodes &&
(sortedBy === "date" || sortedBy === "score")
) {
// this is in the case when NO filters are provided, to avoid doing the joins on the whole table when we will only keep 100 results in the end
// still doing a limit of 5000 because they will be aggregated by ROME and siret
return qb
.orderBy(
sortedBy === "date" ? "update_date" : "score",
"desc",
)
.limit(5000);
}
return qb;
},
).as("e"),
)
.innerJoin(
Expand Down

0 comments on commit 5bef8b7

Please sign in to comment.