Purging not working: purge all reports older than now() every 5 seconds

Hi there! I’m trying to teach myself purging by reading up on the docs. To start, I created a purge rule in my app_settings.json that looks like this:

"purge": {
    "fn": "function(userCtx, contact, reports, messages) { const old = Date.now(); return reports.filter(r => r.reported_date < old).map(r => r._id);}",
    "text_expression": "every 5 seconds"
  },

I’ve ensured I’ve pushed it to my instance:

cht --url=https://medic:password@192-168-68-26.my.local-ip.co upload-app-settings

and at first, I thought it worked because it immediately purged some reports I had for my offline test user. However, then I created another report and synchronized (even 3 or 4 (10!!) times to be sure), but the reports were still showing for my offline user. Even more oddly, the report showed as being purged! Here’s a screenshot showing report ID 52c24f39-eadd-4979-9346-87718e2122d1 as having been purged, but still avail to the offline user (they’re two different browser containers, don’t worry ; )

Eventually, the report will get purged. Maybe 10 or 15 min later?

I for sure assume that a purge time of “every 5 seconds” is comically short for any realistic deployment, but having something longer makes it harder to learn purging. Maybe there’s a way to create reports with specific creation times and then continually re-upload them to test that way?

Any advice is much appreciated!

Hi @mrjones
Did you also refresh the page after synchronizing? The actual deletion of the purged documents requires a refresh.
Depending on how many documents need to be deleted (new purges), it can be time consuming and view indexes need to be updated. This is why purging only happens when the app starts up. More details in the docs.

Thanks for the tips @diana - I’ll give it another go and report back my findings.