Process array values concurrently
This commit is contained in:
parent
89867e9bfb
commit
dc22d4e40e
3 changed files with 19 additions and 14 deletions
|
@ -7,6 +7,7 @@ use crate::sql::idiom::Idiom;
|
|||
use crate::sql::part::Part;
|
||||
use crate::sql::value::Value;
|
||||
use async_recursion::async_recursion;
|
||||
use futures::future::try_join_all;
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl Value {
|
||||
|
@ -43,9 +44,9 @@ impl Value {
|
|||
Ok(())
|
||||
}
|
||||
_ => {
|
||||
for v in &mut v.value {
|
||||
v.del(ctx, opt, exe, &path.next()).await?;
|
||||
}
|
||||
let pth = path.next();
|
||||
let fut = v.value.iter_mut().map(|v| v.del(&ctx, opt, exe, &pth));
|
||||
try_join_all(fut).await?;
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
|
@ -99,9 +100,10 @@ impl Value {
|
|||
Ok(())
|
||||
}
|
||||
_ => {
|
||||
let pth = path.next();
|
||||
for v in &mut v.value {
|
||||
if w.compute(ctx, opt, exe, Some(&v)).await?.is_truthy() {
|
||||
v.del(ctx, opt, exe, &path.next()).await?;
|
||||
v.del(ctx, opt, exe, &pth).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -8,6 +8,7 @@ use crate::sql::part::Part;
|
|||
use crate::sql::statements::select::SelectStatement;
|
||||
use crate::sql::value::{Value, Values};
|
||||
use async_recursion::async_recursion;
|
||||
use futures::future::try_join_all;
|
||||
|
||||
impl Value {
|
||||
#[async_recursion]
|
||||
|
@ -32,11 +33,9 @@ impl Value {
|
|||
// Current path part is an array
|
||||
Value::Array(v) => match p {
|
||||
Part::All => {
|
||||
let mut a = Vec::new();
|
||||
for v in &v.value {
|
||||
a.push(v.get(ctx, opt, exe, &path.next()).await?)
|
||||
}
|
||||
Ok(a.into())
|
||||
let pth = path.next();
|
||||
let fut = v.value.iter().map(|v| v.get(&ctx, opt, exe, &pth));
|
||||
try_join_all(fut).await.map(|v| v.into())
|
||||
}
|
||||
Part::First => match v.value.first() {
|
||||
Some(v) => v.get(ctx, opt, exe, &path.next()).await,
|
||||
|
@ -51,10 +50,11 @@ impl Value {
|
|||
None => Ok(Value::None),
|
||||
},
|
||||
Part::Where(w) => {
|
||||
let pth = path.next();
|
||||
let mut a = Vec::new();
|
||||
for v in &v.value {
|
||||
if w.compute(ctx, opt, exe, Some(&v)).await?.is_truthy() {
|
||||
a.push(v.get(ctx, opt, exe, &path.next()).await?)
|
||||
a.push(v.get(ctx, opt, exe, &pth).await?)
|
||||
}
|
||||
}
|
||||
Ok(a.into())
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::sql::object::Object;
|
|||
use crate::sql::part::Part;
|
||||
use crate::sql::value::Value;
|
||||
use async_recursion::async_recursion;
|
||||
use futures::future::try_join_all;
|
||||
|
||||
impl Value {
|
||||
#[async_recursion]
|
||||
|
@ -37,9 +38,10 @@ impl Value {
|
|||
// Current path part is an array
|
||||
Value::Array(v) => match p {
|
||||
Part::All => {
|
||||
for v in &mut v.value {
|
||||
v.set(ctx, opt, exe, &path.next(), val.clone()).await?;
|
||||
}
|
||||
let pth = path.next();
|
||||
let fut =
|
||||
v.value.iter_mut().map(|v| v.set(ctx, opt, exe, &pth, val.clone()));
|
||||
try_join_all(fut).await?;
|
||||
Ok(())
|
||||
}
|
||||
Part::First => match v.value.first_mut() {
|
||||
|
@ -55,9 +57,10 @@ impl Value {
|
|||
None => Ok(()),
|
||||
},
|
||||
Part::Where(w) => {
|
||||
let pth = path.next();
|
||||
for v in &mut v.value {
|
||||
if w.compute(ctx, opt, exe, Some(&v)).await?.is_truthy() {
|
||||
v.set(ctx, opt, exe, &path.next(), val.clone()).await?;
|
||||
v.set(ctx, opt, exe, &pth, val.clone()).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue