Open artfabrique opened 5 years ago
I'll try to break batches via using dispatch("batchSync")
between two array operations. Supposedly it should send all accumulated updates to the firestore.
any updates on that issue?
Having a similar Issue here
So after having looked into this, apparently the way I was merging two arrayUnions on a patch call has broke because of the way the Firebase SDK works changed slightly.
https://github.com/mesqueeb/vuex-easy-firestore/blob/master/src/module/actions.ts#L106
While I work on the solution, for now please dispatch('batchSync')
in between any arrayUnion or arrayRemove calls.
I'll change the library to queue arrayUnions and arrayRemoves in the shape of my own class wrappers, then only once the queue finished and the changes are pushed to Firebase I will convert the class wrapper to the actual Firebase FieldValue. This way I can merge multiple calls correctly without the danger of it breaking again in the future.
Hi. I have further looked into this. I couldn't solve this properly since the Firebase SDK doesn't allow to send a payload with both ArrayRemove and ArrayUnion. Simply because the data object with the updates would have a duplicate key... eg.
{
id: "myID",
myArr: arrayUnion(newElement),
myArr: arrayRemove(otherElement),
}
I couldn't find a way to merge both of these updates into 1 batch...
For now: stick to doing dispatch('batchSync')
in between calls.
In the future: I'm thinking of making vuex updates immediately and spreading out firestore sync over multiple batches automatically whenever there's a conflict between both arrayUnion and ArrayRemove.
Will update here later.
After about two years of open source, I finally got accepted for Github Sponsors!
A little about me:
BTW, donations get's paid DOUBLE by GitHub! (they're alchemists... 🦾)
How to reproduce
Try to perform this sequential dispatches;
As a result, we will have a single batched update from V.E.F. and only first used method will be put into
_methodName
prop of the update. In this particular case the result of batched V.E.F. update will be:If I offset the second dispatch in time with
setTimemout(5000)
and it falls into the next batch all works as expected.