From c4720b64077e9633399c723f16061d35e1cb8066 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Fri, 23 Feb 2024 08:55:21 +1300 Subject: [PATCH] Allow scraper-like filters up to limit=100 or time ranges of 1 hour or less (not yet efficient) --- chorus-lib/src/store/mod.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/chorus-lib/src/store/mod.rs b/chorus-lib/src/store/mod.rs index 5442efd..8a9e033 100644 --- a/chorus-lib/src/store/mod.rs +++ b/chorus-lib/src/store/mod.rs @@ -389,10 +389,19 @@ impl Store { } } } - } else if self.allow_scraping || filter.limit() <= 10 { + } else { + let maxtime = filter.until().0.min(Time::now().0); + let allow = + self.allow_scraping || filter.limit() <= 100 || (maxtime - filter.since().0) < 3600; + if !allow { + return Err(ChorusError::Scraper.into()); + } + + // FIXME: we can use akci to scan author + time + // we can use ktci to scan kind + time + // (but we have no index yet to scan tag + time) + // This is INEFFICIENT as it scans through EVERY EVENT - // but the filter is a scraper and we don't have a lot of support - // for scrapers. let mut count = 0; let txn = self.env.read_txn()?; let iter = self.ci.iter(&txn)?; @@ -408,8 +417,6 @@ impl Store { } } } - } else { - return Err(ChorusError::Scraper.into()); } Ok(output)