0

My View show some data subscribed to a realm publisher. So if I insert some new objects to the realm db, the realm publisher will send a new data list to the subscriber and the view will be refreshed.

The problem is that when I insert N data into realm db, the publisher will send a new data list to the subscriber for each inserted object. As a result, the view will be refreshed N times which will cause a CPU peek.

Is there any method to control the frequency of the realm publisher?

Thanks

  • 1
    Are you doing a write within a single transaction (a write closure) or are you doing multiple writes, as in one write per object? Do you have some example code? Please take a moment and review [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Jay Dec 13 '21 at 20:10
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 19 '21 at 06:51
  • @Jay Thanks for your insight, I've tried to write multiple objects within one write transaction, and it solved my problem. Really Thanks! – Geoffrey Chen Dec 24 '21 at 14:59

1 Answers1

0

Put a debounce immediately after the realm publisher. I would make it a 0.25 or 0.5 debounce.

Daniel T.
  • 32,821
  • 6
  • 50
  • 72
  • I think the OP needs to use a transaction which eliminates the issue. Debouncing is going to be tough is he's writing one object at a time. – Jay Dec 13 '21 at 20:12