You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed an odd behavior from magnetar in a edge case. It might not be a bug but then I think it could be highlighted in the documentation 🙂
Use case
I have a method to stream a document that looks like this :
constgamesModule=magnetar.collection<Game>(GAMES_COLLECTION,{modifyPayloadOn: {insert: gamesDefaults},modifyReadResponseOn: {added: gamesDefaults},})exportconstgetGame=(id: string)=>{constgameModule=gamesModule.doc(id);gameModule.stream().catch((error)=>{console.error(`Game ${id} stream was closed due to an error`,error);});returngameModule.data;}
Expected result
Magnetar streams the document with the id id. If id is undefined, nothing happens.
Actual result
If, for some reasons, id is undefined (e.g. when the id is a reactive variable and is not yet set), magnetar streams the whole collection. This behavior led me to massive amount of document streams/fetches on my firestore DB (I reached the 50k free quota in 2h).
Workaround
My current solution was to add a check on the value of the id parameter.
exportconstgetGame=(id: string)=>{if(!id)returnundefined;constgameModule=gamesModule.doc(id);gameModule.stream().catch((error)=>{console.error(`Game ${id} stream was closed due to an error`,error);})returngameModule.data;}
Suggestion
I think it would be nice if magnetar could handle undefined document ids natively. Else, it would be good to document this behavior.
Again, I am very grateful for the work you have done here! Thanks to magnetar, I was able to write a soon-to-be-published opensource full-stack pwa in ~3 weeks. This app is going to help my non-profit organisation to manage the games and the players of a real-life game that gathers +1200 boyscouts in Belgium next weekend 😉
The text was updated successfully, but these errors were encountered:
@vdsbenoit
Good catch!!! We should handle this more gracefully and the side effect you found is definitely not what anyone would intend to happen. Open for PRs!
Ps: das cool om te horen! Ik zat ook in de scouts vroeger XD
Hi,
I noticed an odd behavior from magnetar in a edge case. It might not be a bug but then I think it could be highlighted in the documentation 🙂
Use case
I have a method to stream a document that looks like this :
Expected result
Magnetar streams the document with the id
id
. Ifid
isundefined
, nothing happens.Actual result
If, for some reasons,
id
isundefined
(e.g. when the id is a reactive variable and is not yet set), magnetar streams the whole collection. This behavior led me to massive amount of document streams/fetches on my firestore DB (I reached the 50k free quota in 2h).Workaround
My current solution was to add a check on the value of the
id
parameter.Suggestion
I think it would be nice if magnetar could handle undefined document ids natively. Else, it would be good to document this behavior.
Again, I am very grateful for the work you have done here! Thanks to magnetar, I was able to write a soon-to-be-published opensource full-stack pwa in ~3 weeks. This app is going to help my non-profit organisation to manage the games and the players of a real-life game that gathers +1200 boyscouts in Belgium next weekend 😉
The text was updated successfully, but these errors were encountered: