diff --git a/examples/caching_persistent_collections.rs b/examples/caching_persistent_collections.rs index d9794ab..13fbec2 100644 --- a/examples/caching_persistent_collections.rs +++ b/examples/caching_persistent_collections.rs @@ -172,7 +172,7 @@ async fn main() -> Result<(), Box> { }) .order_by([( path!(MyTestStructure::some_num), - FirestoreQueryDirection::Ascending, + FirestoreQueryDirection::Descending, )]) .obj::() .stream_query_with_errors() diff --git a/src/cache/cache_query_engine.rs b/src/cache/cache_query_engine.rs index 0ad77b5..f602170 100644 --- a/src/cache/cache_query_engine.rs +++ b/src/cache/cache_query_engine.rs @@ -18,7 +18,6 @@ impl FirestoreCacheQueryEngine { pub fn params_supported(&self) -> bool { self.query.all_descendants.iter().all(|x| !*x) - && self.query.order_by.is_none() && self.query.start_at.is_none() && self.query.end_at.is_none() && self.query.offset.is_none() @@ -41,7 +40,6 @@ impl FirestoreCacheQueryEngine { ) -> FirestoreResult>> { if let Some(order_by) = &self.query.order_by { let mut collected: Vec = input.try_collect().await?; - collected.sort_by(|doc_a, doc_b| { let mut current_ordering = Ordering::Equal; for sort_field in order_by { diff --git a/src/db/query.rs b/src/db/query.rs index e77c345..1abcd22 100644 --- a/src/db/query.rs +++ b/src/db/query.rs @@ -167,19 +167,32 @@ impl FirestoreDb { Level::DEBUG, "Firestore Query Cached", "/firestore/collection_name" = collection_id.as_str(), + "/firestore/cache_result" = field::Empty, ); - span.in_scope(|| { - debug!("Querying {} documents from cache", collection_id); - }); - let collection_path = if let Some(parent) = params.parent.as_ref() { format!("{}/{}", parent, collection_id) } else { format!("{}/{}", self.get_documents_path(), collection_id.as_str()) }; - cache.query_docs(&collection_path, params).await + let result = cache.query_docs(&collection_path, params).await?; + match result { + FirestoreCachedValue::UseCached(stream) => { + span.record("/firestore/cache_result", "hit"); + span.in_scope(|| { + debug!("Querying {} documents from cache", collection_id); + }); + Ok(FirestoreCachedValue::UseCached(stream)) + } + FirestoreCachedValue::SkipCache => { + span.record("/firestore/cache_result", "miss"); + span.in_scope(|| { + debug!("Querying {} documents from cache skipped", collection_id); + }); + Ok(FirestoreCachedValue::SkipCache) + } + } } else { Ok(FirestoreCachedValue::SkipCache) }