Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.49k stars 589 forks source link

Best way to update multiple documents at once? #236

Closed cesargdm closed 5 years ago

cesargdm commented 5 years ago

I make an updates to Watermelon after I upload local objects to my backend, since I call Promise.all() the network requests are made concurrent and In my code I call the update method like this:

...
if (response?.data?.unitId) {
  await database.action(async () => {
    await wmUnitService.update((unitService) => {
      unitService.uploaded = true
    })
  })

  return Promise.resolve(response?.data?.unitId)
}

And then the response is made, I get the warning The action you're trying to perform (unnamed) can't be performed yet, beacuse there are 4 actions in the queue. Current action: unnamed. Ignore this message if everything is working fine. But if your actions are not running, it's because the current action is stuck. No updates are thrown off, but I'm curious if I this action can be handled better.

radex commented 5 years ago

this is covered in the docs: https://github.com/Nozbe/WatermelonDB/blob/master/docs/Actions.md

radex commented 5 years ago

@cesargdm let me know if the issue is fixed

cesargdm commented 5 years ago

@radex Just the trick in my case is that the actions can be fired at random, because I may recieve 3 responses and a moment after 5 more, and just before 10 more... So that's why I'm getting the warning. So I was just looking for a way to prepare Watermelon for this if there was anyway. If not, I can just close the issue. It's really not being a issue for me.

radex commented 5 years ago

No, if it's not an issue, then it's not really an issue. The warning is just like it says — a warning of a POTENTIAL problem. If you'd like, you could contribute an improvement that the warning is only showed after a certain timeout — say, 1 or 5 seconds.