digidem / mapeo-core-next

The upcoming version of Mapeo Core
MIT License
7 stars 1 forks source link

chore: throttle pre-have updates to avoid network flooding #626

Closed EvanHahn closed 2 months ago

EvanHahn commented 2 months ago

Followup to 6ad3beaaff8d10d4a23a52380e73d8f76c833928. If we're adding lots of data at once (like during a config import), we shouldn't flood the network.

See this comment.

EvanHahn commented 2 months ago

I'll merge this next week to give @gmaclennan a chance to chime in.

gmaclennan commented 2 months ago

I would lean towards debouncing rather than throttling for this, with a shorter delay.

During imports (e.g. lots of additions to the DB), we only really want to send one pre-have, when it completes. For the user actually recording data, e.g. saving an observation, we want the prehave to be sent soon after they save.

I suggest a debounce of 1000ms. That should result in imports (e.g. config import) just sending a single pre-have, and for user created data, the prehave will be sent within 1 second of them saving, which should feel "snappy" to most users I think.

EvanHahn commented 2 months ago

Changed to a 1000ms debounce. I'll land if CI passes.