Skip to content

Commit 7106eae

Browse files
committed
Run Condition::build twice and only collect joins during the first run
Fixes #80
1 parent 2d52e58 commit 7106eae

File tree

1 file changed

+22
-1
lines changed
  • src/internal/query_context

1 file changed

+22
-1
lines changed

src/internal/query_context/mod.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,15 @@ impl<'v> QueryContext<'v> {
116116
///
117117
/// (Use the index with [`QueryContext::get_condition`])
118118
pub fn add_condition(&mut self, condition: &(impl Condition<'v> + ?Sized)) -> usize {
119+
condition.build(ConditionBuilder {
120+
context: self,
121+
only_accept_paths: true,
122+
});
119123
let index = self.conditions.len();
120-
condition.build(ConditionBuilder { context: self });
124+
condition.build(ConditionBuilder {
125+
context: self,
126+
only_accept_paths: false,
127+
});
121128
self.span.in_scope(|| {
122129
trace!(
123130
condition = ?self.conditions.get(index..),
@@ -411,22 +418,32 @@ impl QueryContext<'_> {
411418
/// A [`&mut QueryContext`] with restricted API which is passed to [`Condition::build`]
412419
pub struct ConditionBuilder<'r, 'v> {
413420
context: &'r mut QueryContext<'v>,
421+
only_accept_paths: bool,
414422
}
415423

416424
impl<'v> ConditionBuilder<'_, 'v> {
417425
pub(crate) fn reborrow<'r>(&'r mut self) -> ConditionBuilder<'r, 'v> {
418426
ConditionBuilder::<'r, 'v> {
419427
context: &mut *self.context,
428+
only_accept_paths: self.only_accept_paths,
420429
}
421430
}
422431

423432
pub(crate) fn push_condition(&mut self, condition: FlatCondition) -> usize {
433+
if self.only_accept_paths {
434+
return usize::MAX;
435+
}
436+
424437
let index = self.context.conditions.len();
425438
self.context.conditions.push(condition);
426439
index
427440
}
428441

429442
pub(crate) fn pop_condition(&mut self) {
443+
if self.only_accept_paths {
444+
return;
445+
}
446+
430447
self.context.conditions.pop();
431448
}
432449

@@ -435,6 +452,10 @@ impl<'v> ConditionBuilder<'_, 'v> {
435452
}
436453

437454
pub(crate) fn push_value(&mut self, value: Value<'v>) -> usize {
455+
if self.only_accept_paths {
456+
return usize::MAX;
457+
}
458+
438459
let index = self.context.values.len();
439460
self.context.values.push(value);
440461
index

0 commit comments

Comments
 (0)