From 39a945b4935a0fe0e86d547e09ae1d3af8015971 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Wed, 4 Jan 2023 16:51:17 -0600 Subject: [PATCH] perf: separate author/delegated_by queries, minor improvement --- src/db.rs | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/db.rs b/src/db.rs index b645fdc..bed22b1 100644 --- a/src/db.rs +++ b/src/db.rs @@ -529,22 +529,42 @@ fn query_from_filter(f: &ReqFilter) -> (String, Vec>) { for auth in authvec { match hex_range(auth) { Some(HexSearch::Exact(ex)) => { - auth_searches.push("author=? OR delegated_by=?".to_owned()); - params.push(Box::new(ex.clone())); + auth_searches.push("author=?".to_owned()); params.push(Box::new(ex)); } Some(HexSearch::Range(lower, upper)) => { auth_searches.push( - "(author>? AND author? AND delegated_by? AND author { - auth_searches.push("author>? OR delegated_by>?".to_owned()); - params.push(Box::new(lower.clone())); + auth_searches.push("author>?".to_owned()); + params.push(Box::new(lower)); + } + None => { + info!("Could not parse hex range from author {:?}", auth); + } + } + } + // take each author and convert to a hexsearch + let mut del_searches: Vec = vec![]; + for auth in authvec { + match hex_range(auth) { + Some(HexSearch::Exact(ex)) => { + del_searches.push("delegated_by=?".to_owned()); + params.push(Box::new(ex)); + } + Some(HexSearch::Range(lower, upper)) => { + del_searches.push( + "(delegated_by>? AND delegated_by { + del_searches.push("delegated_by>?".to_owned()); params.push(Box::new(lower)); } None => { @@ -553,13 +573,12 @@ fn query_from_filter(f: &ReqFilter) -> (String, Vec>) { } } if !authvec.is_empty() { - let authors_clause = format!("({})", auth_searches.join(" OR ")); - filter_components.push(authors_clause); + // combine auth_searches and del_searches + let comb_clause = format!("({} OR {})", auth_searches.join(" OR "), del_searches.join(" OR ")); + filter_components.push(comb_clause); } else { - // if the authors list was empty, we should never return - // any results. - filter_components.push("false".to_owned()); - } + filter_components.push("false".to_owned()); + } } // Query for Kind if let Some(ks) = &f.kinds {