Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Oct 6, 2023
1 parent 70e8efe commit 8f328d9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/caching_persistent_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
})
.order_by([(
path!(MyTestStructure::some_num),
FirestoreQueryDirection::Ascending,
FirestoreQueryDirection::Descending,
)])
.obj::<MyTestStructure>()
.stream_query_with_errors()
Expand Down
2 changes: 0 additions & 2 deletions src/cache/cache_query_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -41,7 +40,6 @@ impl FirestoreCacheQueryEngine {
) -> FirestoreResult<BoxStream<'b, FirestoreResult<FirestoreDocument>>> {
if let Some(order_by) = &self.query.order_by {
let mut collected: Vec<FirestoreDocument> = input.try_collect().await?;

collected.sort_by(|doc_a, doc_b| {
let mut current_ordering = Ordering::Equal;
for sort_field in order_by {
Expand Down
23 changes: 18 additions & 5 deletions src/db/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 8f328d9

Please sign in to comment.