Skip to content

Commit ee55ba2

Browse files
committed
perf(query-compiler): skip search merge for no-search groups
Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent c595dc0 commit ee55ba2

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • query-compiler/core/src/query_graph_builder/extractors/filters

query-compiler/core/src/query_graph_builder/extractors/filters/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ where
228228
/// 3. We reconstruct the filter tree and merge the search filters that have the same query along the way
229229
/// eg: `Filter(And([SearchFilter("query", [FieldA]), SearchFilter("query", [FieldB])]))` -> `Filter(And([SearchFilter("query", [FieldA, FieldB])]))`
230230
fn merge_search_filters(filter: Filter) -> Filter {
231+
if matches!(filter, Filter::And(_) | Filter::Or(_) | Filter::Not(_)) && !contains_search_filter(&filter) {
232+
return filter;
233+
}
234+
231235
// The filter tree _needs_ to be flattened for the merge to work properly
232236
let flattened = fold_filter(filter);
233237

@@ -239,6 +243,19 @@ fn merge_search_filters(filter: Filter) -> Filter {
239243
}
240244
}
241245

246+
fn contains_search_filter(filter: &Filter) -> bool {
247+
match filter {
248+
Filter::Scalar(sf) => matches!(
249+
sf.condition,
250+
ScalarCondition::Search(..) | ScalarCondition::NotSearch(..)
251+
),
252+
Filter::And(filters) | Filter::Or(filters) | Filter::Not(filters) => {
253+
filters.iter().any(contains_search_filter)
254+
}
255+
_ => false,
256+
}
257+
}
258+
242259
fn fold_search_filters(filters: &[Filter]) -> Vec<Filter> {
243260
let mut filters_by_val: HashMap<PrismaValue, &Filter> = HashMap::new();
244261
let mut projections_by_val: HashMap<PrismaValue, Vec<ScalarProjection>> = HashMap::new();

0 commit comments

Comments
 (0)