Improve performance of embedded field path creation
This commit is contained in:
parent
c4386f1549
commit
27a01bec08
6 changed files with 23 additions and 24 deletions
|
@ -20,11 +20,11 @@ impl<'a> Document<'a> {
|
|||
// Loop through all field statements
|
||||
for fd in self.fd(opt, txn).await?.iter() {
|
||||
// Loop over each field in document
|
||||
for k in self.current.each(&fd.name).into_iter() {
|
||||
for k in self.current.each(&fd.name).iter() {
|
||||
// Get the initial value
|
||||
let old = self.initial.pick(&k);
|
||||
let old = self.initial.pick(k);
|
||||
// Get the current value
|
||||
let mut val = self.current.pick(&k);
|
||||
let mut val = self.current.pick(k);
|
||||
// Check for a VALUE clause
|
||||
if let Some(expr) = &fd.value {
|
||||
// Configure the context
|
||||
|
@ -113,9 +113,9 @@ impl<'a> Document<'a> {
|
|||
}
|
||||
// Set the value of the field
|
||||
match val {
|
||||
Value::None => self.current.to_mut().del(ctx, opt, txn, &k).await?,
|
||||
Value::Void => self.current.to_mut().del(ctx, opt, txn, &k).await?,
|
||||
_ => self.current.to_mut().set(ctx, opt, txn, &k, val).await?,
|
||||
Value::None => self.current.to_mut().del(ctx, opt, txn, k).await?,
|
||||
Value::Void => self.current.to_mut().del(ctx, opt, txn, k).await?,
|
||||
_ => self.current.to_mut().set(ctx, opt, txn, k, val).await?,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,21 +115,21 @@ impl<'a> Document<'a> {
|
|||
// Loop through all field statements
|
||||
for fd in self.fd(opt, txn).await?.iter() {
|
||||
// Loop over each field in document
|
||||
for k in out.each(&fd.name).into_iter() {
|
||||
for k in out.each(&fd.name).iter() {
|
||||
// Process field permissions
|
||||
match &fd.permissions.select {
|
||||
Permission::Full => (),
|
||||
Permission::None => out.del(ctx, opt, txn, &k).await?,
|
||||
Permission::None => out.del(ctx, opt, txn, k).await?,
|
||||
Permission::Specific(e) => {
|
||||
// Get the current value
|
||||
let val = self.current.pick(&k);
|
||||
let val = self.current.pick(k);
|
||||
// Configure the context
|
||||
let mut ctx = Context::new(ctx);
|
||||
ctx.add_value("value".into(), val);
|
||||
let ctx = ctx.freeze();
|
||||
// Process the PERMISSION clause
|
||||
if !e.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
|
||||
out.del(&ctx, opt, txn, &k).await?
|
||||
out.del(&ctx, opt, txn, k).await?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,10 +57,9 @@ impl From<Vec<Part>> for Idiom {
|
|||
}
|
||||
|
||||
impl Idiom {
|
||||
pub fn add(&self, n: Part) -> Idiom {
|
||||
let mut p = self.parts.to_vec();
|
||||
p.push(n);
|
||||
Idiom::from(p)
|
||||
pub fn add(mut self, n: Part) -> Idiom {
|
||||
self.parts.push(n);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn to_path(&self) -> String {
|
||||
|
|
|
@ -13,7 +13,7 @@ impl Value {
|
|||
if !b.value.contains_key(key) {
|
||||
ops.push(Operation {
|
||||
op: Op::Remove,
|
||||
path: path.add(key.clone().into()),
|
||||
path: path.clone().add(key.clone().into()),
|
||||
value: Value::Null,
|
||||
})
|
||||
}
|
||||
|
@ -23,11 +23,11 @@ impl Value {
|
|||
match a.value.get(key) {
|
||||
None => ops.push(Operation {
|
||||
op: Op::Add,
|
||||
path: path.add(key.clone().into()),
|
||||
path: path.clone().add(key.clone().into()),
|
||||
value: val.clone(),
|
||||
}),
|
||||
Some(old) => {
|
||||
let path = path.add(key.clone().into());
|
||||
let path = path.clone().add(key.clone().into());
|
||||
ops.append(&mut old.diff(val, path))
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ impl Value {
|
|||
(Value::Array(a), Value::Array(b)) if a != b => {
|
||||
let mut n = 0;
|
||||
while n < min(a.len(), b.len()) {
|
||||
let path = path.add(n.into());
|
||||
let path = path.clone().add(n.into());
|
||||
ops.append(&mut a.value[n].diff(&b.value[n], path));
|
||||
n += 1;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ impl Value {
|
|||
if n >= a.len() {
|
||||
ops.push(Operation {
|
||||
op: Op::Add,
|
||||
path: path.add(n.into()),
|
||||
path: path.clone().add(n.into()),
|
||||
value: b.value[n].clone(),
|
||||
})
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ impl Value {
|
|||
if n >= b.len() {
|
||||
ops.push(Operation {
|
||||
op: Op::Remove,
|
||||
path: path.add(n.into()),
|
||||
path: path.clone().add(n.into()),
|
||||
value: Value::Null,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ impl Value {
|
|||
.value
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(i, v)| v._each(path.next(), prev.add(Part::from(i))))
|
||||
.flat_map(|(i, v)| v._each(path.next(), prev.clone().add(Part::from(i))))
|
||||
.collect::<Vec<_>>(),
|
||||
Part::First => match v.value.first() {
|
||||
Some(v) => v._each(path.next(), prev.add(p.clone())),
|
||||
|
@ -44,7 +44,7 @@ impl Value {
|
|||
.value
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(i, v)| v._each(path.next(), prev.add(Part::from(i))))
|
||||
.flat_map(|(i, v)| v._each(path.next(), prev.clone().add(Part::from(i))))
|
||||
.collect::<Vec<_>>(),
|
||||
},
|
||||
// Ignore everything else
|
||||
|
|
|
@ -12,14 +12,14 @@ impl Value {
|
|||
Value::Object(v) => v
|
||||
.value
|
||||
.iter()
|
||||
.flat_map(|(k, v)| v._every(prev.add(Part::from(k))))
|
||||
.flat_map(|(k, v)| v._every(prev.clone().add(Part::from(k))))
|
||||
.collect::<Vec<_>>(),
|
||||
// Current path part is an array
|
||||
Value::Array(v) => v
|
||||
.value
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(i, v)| v._every(prev.add(Part::from(i))))
|
||||
.flat_map(|(i, v)| v._every(prev.clone().add(Part::from(i))))
|
||||
.collect::<Vec<_>>(),
|
||||
// Process everything else
|
||||
_ => vec![prev],
|
||||
|
|
Loading…
Reference in a new issue