Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should automatically split batches per 500 documents #324

Open
mardonedias opened this issue Apr 26, 2020 · 8 comments
Open

should automatically split batches per 500 documents #324

mardonedias opened this issue Apr 26, 2020 · 8 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@mardonedias
Copy link

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
Copy link
Author

mardonedias commented Apr 26, 2020

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
Copy link
Owner

@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. 🦜

@mesqueeb mesqueeb added the bug Something isn't working label Apr 27, 2020
@mesqueeb mesqueeb changed the title The library only inserts a maximum of 500 documents should automatically split batches per 500 documents Apr 27, 2020
@mesqueeb mesqueeb added the help wanted Extra attention is needed label May 4, 2020
@louisameline
Copy link
Collaborator

louisameline commented May 11, 2020

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
Copy link
Author

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
Copy link
Owner

mesqueeb commented May 12, 2020

@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
Copy link
Author

// 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
Copy link

RichardCr commented Mar 13, 2023

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 mesqueeb reopened this Mar 15, 2023
@mesqueeb
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants