2

I'm looking for a way to replicate an rxdb instance locally, in the browser (local storage to local storage). I read somewhere that this is the only way to purge deleted items (can't find the link now). Actually, what I would like to do is:

  • purge deleted items (deleted flag set)
  • purge old revisions (older than a certain timestamp) However I can't find an example of how to do this. I need to purge often because my data changes very often and I would quickly outrun browser storage (as well as rows in my remote database that I'm syncing to).

This is my rough idea based on rxdb docs:

// transfer data
const jsonResult = await myCurrentDb.things.dump()
const filteredJsonResult = jsonResult.filter(_ => !(_.deleted) && <latestRevision>)

// wipe current collection
await myCurrentDb.things.remove()
await myCurrentDB.collection({name: 'things', ... }) // recreate

// re-import
myCurrentDb.things.importDump(filteredJsonResult)

Questions:

  1. I am thinking of running this clientside, intermittently (maybe once every 30 minutes?) Would this approach be OK? Am I missing something or is dump/importDump not the way to go?
  2. I need help figuring out the logic for the "latestRevision" condition in the filter? How do I figure that out?
yen
  • 1,769
  • 2
  • 15
  • 43
  • Your approach to `_deleted` is fine, but you're going have mess juggling `_rev`. I recommend investigating [revs_limit](https://pouchdb.com/api.html#create_database) using a reasonable threshold instead. – RamblinRose Oct 23 '20 at 12:53
  • @RamblinRose thanks for this! I did not know about `revs_limit`; will def make use of it. Wish there were some sort of guidance metrics... like _if users make an average of R revisions to an object per day, and are simultaneously logged in at L different places, your min rev_limit should be N_ before syncing functionality degrades noticeably. That sort of thing. – yen Oct 24 '20 at 22:28
  • Regarding metrics, that is specific to your use-case. I doubt a one-size-fits-all solution exists. You've outlined reasonable parameters. Good luck! – RamblinRose Oct 25 '20 at 13:00

0 Answers0