From 90dfa9f49f2a3a0e03290b477a956e7fa8c92c61 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 9 Jul 2022 19:44:15 +0100 Subject: [PATCH] Ensure LIMIT BY clause does not cause query to fail --- lib/src/dbs/channel.rs | 16 ++++++++++++---- lib/src/dbs/iterate.rs | 16 ++++++++++++---- lib/src/fnc/script/main.rs | 4 +++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/src/dbs/channel.rs b/lib/src/dbs/channel.rs index 603a879e..b3b35032 100644 --- a/lib/src/dbs/channel.rs +++ b/lib/src/dbs/channel.rs @@ -78,7 +78,9 @@ impl Iterable { // Loop until no more keys loop { // Check if the context is finished - ctx.check()?; + if ctx.is_done() { + break; + } // Get the next 1000 key-value entries let res = match nxt { None => { @@ -104,7 +106,9 @@ impl Iterable { // Loop over results for (i, (k, v)) in res.into_iter().enumerate() { // Check the context - ctx.check()?; + if ctx.is_done() { + break; + } // Ready the next if n == i + 1 { nxt = Some(k.clone()); @@ -199,7 +203,9 @@ impl Iterable { // Loop until no more keys loop { // Check if the context is finished - ctx.check()?; + if ctx.is_done() { + break; + } // Get the next 1000 key-value entries let res = match nxt { None => { @@ -225,7 +231,9 @@ impl Iterable { // Loop over results for (i, (k, _)) in res.into_iter().enumerate() { // Check the context - ctx.check()?; + if ctx.is_done() { + break; + } // Ready the next if n == i + 1 { nxt = Some(k.clone()); diff --git a/lib/src/dbs/iterate.rs b/lib/src/dbs/iterate.rs index dc1ed709..c1d66e58 100644 --- a/lib/src/dbs/iterate.rs +++ b/lib/src/dbs/iterate.rs @@ -78,7 +78,9 @@ impl Iterable { // Loop until no more keys loop { // Check if the context is finished - ctx.check()?; + if ctx.is_done() { + break; + } // Get the next 1000 key-value entries let res = match nxt { None => { @@ -104,7 +106,9 @@ impl Iterable { // Loop over results for (i, (k, v)) in res.into_iter().enumerate() { // Check the context - ctx.check()?; + if ctx.is_done() { + break; + } // Ready the next if n == i + 1 { nxt = Some(k.clone()); @@ -199,7 +203,9 @@ impl Iterable { // Loop until no more keys loop { // Check if the context is finished - ctx.check()?; + if ctx.is_done() { + break; + } // Get the next 1000 key-value entries let res = match nxt { None => { @@ -225,7 +231,9 @@ impl Iterable { // Loop over results for (i, (k, _)) in res.into_iter().enumerate() { // Check the context - ctx.check()?; + if ctx.is_done() { + break; + } // Ready the next if n == i + 1 { nxt = Some(k.clone()); diff --git a/lib/src/fnc/script/main.rs b/lib/src/fnc/script/main.rs index a725773f..aa72b5a2 100644 --- a/lib/src/fnc/script/main.rs +++ b/lib/src/fnc/script/main.rs @@ -12,7 +12,9 @@ pub async fn run( doc: Option<&Value>, ) -> Result { // Check the context - let _ = ctx.check()?; + if ctx.is_done() { + return Ok(Value::None); + } // Create a new agent let exe = Executor::default(); // Create an JavaScript context