mesqueeb / vuex-easy-firestore

Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!
https://mesqueeb.github.io/vuex-easy-firestore
MIT License
234 stars 28 forks source link

should automatically split batches per 500 documents #324

Open mardonedias opened 4 years ago

mardonedias commented 4 years ago

Hello,

I have a problem and I can't solve it. At some point I will need to add what can reach 1000 documents.

The problem is as follows: either dispatch ('myModule / insert', doc) or dispatch ('moduleName / insertBatch', docs), 500 are inserted. I don't know how to solve it, I don't understand why.

const docs = [// more 500 docs]
store.dispatch('colaborador/insertBatch', docs);

// result insert only 500 docs

docs.forEach((item: any) => {
    store.dispatch('colaborador/insert', item );
});

// result insert only 500 docs

can anybody help me?

mardonedias commented 4 years ago

I managed to solve with store.dispatch ('collaborator / insertBatch', docs);

I broke my list into smaller pieces and ran several batches. it worked just like the firebase api.

But, the insert command executed in a loop is limited to 500 inserts. Should that be so? Shouldn't the library break automatically?

`` docs.forEach ((item: any) => {      store.dispatch ('collaborator / insert', item); });

// result insert only 500 docs ``

mesqueeb commented 4 years ago

@mardonedias hi. thanks for your issue! I have written logic that will automatically queue the next batch of inserts, but perhaps it's not being triggered. I'll add some tests for this and let you know if I can find and fix the bug.

--
Vuex Easy Firestore was made with ♥ by Luca Ban.
If you use this library in your projects, you can support the maintenance of this library by a small contribution via Github 💜.
You can also reach out on twitter if you want a one-on-one coding review/lesson. 🦜

louisameline commented 4 years ago

It's funny, I might have solved this today without actually running into the issue myself. I just happened to browse the code for something else and saw some code, I was like "Huh I don't think this would work" x) Please try to clone my repo and checkout the batchFix branch, and see if it works better? I have not tested. If by any luck it works for you, we'll just add a test and merge. Thanks! https://github.com/louisameline/vuex-easy-firestore/tree/batchFix

mardonedias commented 4 years ago

Hello,

It is very specific functionality to import this amount of record at once. In my case I need to get data from a spreadsheet that can easily reach 1500 rows.

I did a test with the dispatch action ('moduleName / insertBatch', docs). The problem persists, only one batch with 500 records is executed.

Captura de tela de 2020-05-12 09-19-27

The problem also occurs when removing dispatch ('moduleName / deleteBatch', ids), only 500 records are removed at a time.

I took the test to confirm. In the case of exclusion, I tried to use the same strategy that I used in the insertion, breaking the data into smaller pieces. But, it does not delete more than 500 records in the same command.

This tool is exceptional, it makes the job very simple.

mesqueeb commented 4 years ago

@mardonedias since @louisameline's change is non-breaking, do you want me to push the change to the latest version on NPM so you can test by just updating? Or did you manage to test his forked repository?

Edit: yes I see in your screenshot now, you did use his fork. And your problem persisted, right?

Edit2: Please try this:

// docs should be more than 500
docs.forEach(doc => $store.dispatch('moduleName/insert', doc))

with @louisameline's branch, WITHOUT using insertBatch!

Let me know!

mardonedias commented 4 years ago

// docs should be more than 500 docs.forEach (doc => $ store.dispatch ('moduleName / insert', doc))

Only enter the 500.

Captura de tela de 2020-05-12 09-51-09

Captura de tela de 2020-05-12 09-51-04

RichardCr commented 1 year ago

Ancient thread, but the reason is firebase. It only accepts batches of 500 at a time. The best way to do this is to use cloud functions and then use a cloud function to update firebase. I can be more explicit if anyone needs more help.

mesqueeb commented 1 year ago

I don't think this is fixed in vuex-easy-firestore 🤔

I solved it in magnetar, the predecessor, i auto batch per 500 and continue making API calls until everything is synced. but never found the time to fix it in vuex-easy-firestore.

Open to PRS!