From ba7f268b990cd17c5d20bf9e0eb6ff77d30fe845 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 3 Jan 2022 18:03:12 +0100 Subject: Rename and change query filters --- src/model/helper/bucket.rs | 3 +-- src/model/key_table.rs | 9 +++++---- src/table/util.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/model/helper/bucket.rs b/src/model/helper/bucket.rs index bb4b5b24..8bc54b3f 100644 --- a/src/model/helper/bucket.rs +++ b/src/model/helper/bucket.rs @@ -116,12 +116,11 @@ impl<'a> BucketHelper<'a> { .get_range( &EmptyKey, None, - Some(KeyFilter::Matches(pattern.to_string())), + Some(KeyFilter::MatchesAndNotDeleted(pattern.to_string())), 10, ) .await? .into_iter() - .filter(|k| !k.state.is_deleted()) .collect::>(); if candidates.len() != 1 { Err(Error::BadRequest(format!( diff --git a/src/model/key_table.rs b/src/model/key_table.rs index daea5473..7afa0337 100644 --- a/src/model/key_table.rs +++ b/src/model/key_table.rs @@ -152,7 +152,7 @@ pub struct KeyTable; #[derive(Clone, Debug, Serialize, Deserialize)] pub enum KeyFilter { Deleted(DeletedFilter), - Matches(String), + MatchesAndNotDeleted(String), } impl TableSchema for KeyTable { @@ -166,10 +166,11 @@ impl TableSchema for KeyTable { fn matches_filter(entry: &Self::E, filter: &Self::Filter) -> bool { match filter { KeyFilter::Deleted(df) => df.apply(entry.state.is_deleted()), - KeyFilter::Matches(pat) => { + KeyFilter::MatchesAndNotDeleted(pat) => { let pat = pat.to_lowercase(); - entry.key_id.to_lowercase().starts_with(&pat) - || entry.name.get().to_lowercase() == pat + !entry.state.is_deleted() + && (entry.key_id.to_lowercase().starts_with(&pat) + || entry.name.get().to_lowercase() == pat) } } } diff --git a/src/table/util.rs b/src/table/util.rs index 043a457c..2a5c3afe 100644 --- a/src/table/util.rs +++ b/src/table/util.rs @@ -19,7 +19,7 @@ impl PartitionKey for EmptyKey { #[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub enum DeletedFilter { - All, + Any, Deleted, NotDeleted, } @@ -27,7 +27,7 @@ pub enum DeletedFilter { impl DeletedFilter { pub fn apply(&self, deleted: bool) -> bool { match self { - DeletedFilter::All => true, + DeletedFilter::Any => true, DeletedFilter::Deleted => deleted, DeletedFilter::NotDeleted => !deleted, } -- cgit v1.2.3