Batch operations and listeners

  • define a listener on a query
  • do multiple updates on documents that fires the listener closure as many times as the number of updates
  • if I regroup all updates into a batch, the listener closure will only be fired once.

Is my understanding correct? (can’t find any documentation referencing this)

No, it doesn’t work that way. Checking a LiveQuery for updates is expensive: it has to run the query again and compare the old and new results. So a LiveQuery doesn’t check immediately when the database posts a change notification. Instead it waits a fraction of a second, and then checks only once no matter how many notifications came in.

It’s still a good idea to use batch updates, but that’s because it makes committing the changes to disk faster.

1 Like