From 0c3232c0563323351770f0a12efcdd8138c6384c Mon Sep 17 00:00:00 2001 From: canonbrother Date: Tue, 22 Oct 2024 11:29:46 +0800 Subject: [PATCH] allow empty --- lib/ain-ocean/src/indexer/mod.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/ain-ocean/src/indexer/mod.rs b/lib/ain-ocean/src/indexer/mod.rs index b991f22c5e..8651af3cb9 100644 --- a/lib/ain-ocean/src/indexer/mod.rs +++ b/lib/ain-ocean/src/indexer/mod.rs @@ -73,17 +73,28 @@ fn index_block_start(services: &Arc, block: &Block) -> Re Some((pool_pair.id, interval, i64::MAX)), SortOrder::Descending, )? - .take(1) .take_while(|item| match item { Ok((k, _)) => k.0 == pool_pair.id && k.1 == interval, _ => true, }) - .map(|e| repository.by_key.retrieve_primary_value(e)) - .collect::>>()?; + .next() + .transpose()?; + + let Some((_, prev_id)) = prevs else { + break; + }; + + let prev = repository + .by_id + .get(&prev_id)?; + + let Some(prev) = prev else { + break; + }; let bucket = get_bucket(block, i64::from(interval)); - if prevs.len() == 1 && prevs[0].bucket >= bucket { + if prev.bucket >= bucket { break; }