Skip to content

Commit 4c36823

Browse files
Merge pull request #3233 from seun-ja/cosmos-key-value-store-exists-downloads-data
selects only id when checking existence of data
2 parents cc1dec2 + 3d8f574 commit 4c36823

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

crates/key-value-azure/src/store.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,18 @@ impl Store for AzureCosmosStore {
190190
}
191191

192192
async fn exists(&self, key: &str) -> Result<bool, Error> {
193-
Ok(self.get_entity::<Key>(key).await?.is_some())
193+
let mut stream = self
194+
.client
195+
.query_documents(Query::new(self.get_id_query(key)))
196+
.query_cross_partition(true)
197+
.max_item_count(1)
198+
.into_stream::<Key>();
199+
200+
match stream.next().await {
201+
Some(Ok(res)) => Ok(!res.results.is_empty()),
202+
Some(Err(e)) => Err(log_error(e)),
203+
None => Ok(false),
204+
}
194205
}
195206

196207
async fn get_keys(&self) -> Result<Vec<String>, Error> {
@@ -446,8 +457,14 @@ impl AzureCosmosStore {
446457
query
447458
}
448459

460+
fn get_id_query(&self, key: &str) -> String {
461+
let mut query = format!("SELECT c.id, c.store_id FROM c WHERE c.id='{key}'");
462+
self.append_store_id(&mut query, true);
463+
query
464+
}
465+
449466
fn get_keys_query(&self) -> String {
450-
let mut query = "SELECT * FROM c".to_owned();
467+
let mut query = "SELECT c.id, c.store_id FROM c".to_owned();
451468
self.append_store_id(&mut query, false);
452469
query
453470
}

0 commit comments

Comments
 (0)