I have a large collection where each document is of a substantial size and therefore cannot be embedded into a single document. For my feature, I need to sort the collection using orderBy
and filter the collection using "array-contains"
and "=="
where the sort and filter parameters are provided by the user. I was wondering if there was an efficient way to do this by cacheing documents that had already been fetched in previous queries. That being said, does firebase do any cacheing itself and does it already optimize what I'm trying to do in this case, or is there any custom cacheing/optimization I can do?
This is what my implementation looks like right now. This works fine for now however it's not very scalable as it creates a new realtime listener each time any of the filter/sort state changes. Is there any way can I improve this to minimize the total number of documents read?
useEffect(() => { if (!sort || !status || !search) return; const unsubscribe = firebase.collection("users") .where("searchTerms", "array-contains", search) .where("status", "==", status) .orderBy(sort) .onSnapshot((snapshot) => { // update state hook with snapshot data... }); return () => unsubscribe(); }, [sort, status, search]);
Thank you for any and all help!
https://stackoverflow.com/questions/67378182/whats-the-most-efficient-and-scalable-way-to-handle-filtering-and-sorting-of-a May 04, 2021 at 10:51AM
没有评论:
发表评论