Client-side Purging - #5075
Conversation
|
Oh yeah, please don't merge 🙃 |
|
Looking good, nice work! A few thoughts...
|
So:
|
|
|
||
| if (!Session.isOnlineOnly()) { | ||
| Purger(); | ||
| } |
There was a problem hiding this comment.
If this delays starting of the app UI, can we have a startup message for this stage?
There was a problem hiding this comment.
It didn't (it spawns of a promise that we ignore), but in other discussions I think we've decided to move it to be an active part of pre-angular startup.
So yeah, it's going to be reworked into be an event emitter so we can follow progress etc
| keys.includes('_rev') && | ||
| keys.includes('_deleted')) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Would it be simpler just to have a _medic_purged: true flag instead of checking for these specific things? Is this doing something clever by deliberately copying pouch/couch soft-delete functionality?
There was a problem hiding this comment.
Yeah I feel more comfortable with this, because it increases the specificity of what we're trying to avoid replicating. It means we can also (for now) do things like block writes of that in validate_doc_update for the server if we're so inclined
| return $q.all([ | ||
| Search('reports', {}, options), | ||
| Search('contacts', {}, options) | ||
| ]) |
There was a problem hiding this comment.
Assuming Search() is slow and that almost all docs are either contacts or reports, would it be quicker to do allDocs() here and then filter manually? Or just hand the filtering off to the custom function?
There was a problem hiding this comment.
It's basically pointless to use search here AFAICT yeah, it's just copying what nools bootstrap does.
Since I'm moving the code to be before angular even starts I am definitely just going to do an all docs in the future
6be639b to
39a5175
Compare
|
@garethbowen / @alxndrsn I moved it to startup. I still need to hook up a progress bar etc so it looks nice. I am also not protecting against documents being deleted that are not yet replicated. It's still not clear to me a safe way of doing this, especially since we're now doing this before angular boots. We could reverse engineer the I think if we really don't want to ship without this feature we are going to have to spend the effort to run the code on the server. |
|
Looking good! Let's chat sometime about the server/client tradeoffs so we can move forward here. |
Can you compare last-replication-time vs |
|
@alxndrsn unless I've missed it we don't store last-replication-time anywhere, it's only available as a live piece of data while angular is running. We could change that so it writes it somewhere (eg to a local doc we do have access to), and then we use that on boot, presuming if that doesn't exist then we are also allowed to purge because it means no real replication has happened yet. However, it's another write, which we're performing on every replication, to solve a check that happens once a month that probably shouldn't need to happen given good rules, and would not be reverted (since we don't need it for anything else) once we moved to server-side. IDK, if people think it's worth it then that's cool and can be done, I personally just didn't have strong interest in it when I was knocking this together. |
|
It's possible doc updates will still be purged before they're replicated because the code only checks the One solution would be to move the code back into the angular app (sorry!) and trigger purging only once replication is completely caught up, but I think the faster execution in bootstrap still wins. The other solution is running server side but we can do that in the next iteration. This approach is good enough for now, do it! |
12965cf to
1713e17
Compare
No messages / progress bar for it yet, that is coming next!
This is a halfway solution to making sure that documents are not purged before they are replicated. When running purge outside of angular it is very challenging to work this out, so instead we just make sure newer docs are not allowed to be purged.
e7f42e6 to
de9e4aa
Compare
|
@garethbowen THE TESTS PASS. I am happy for this to be merged at this stage. I'm currently writing documentation in |
|
NB: I got rid of blocking purges for documents younger than 60 days, because I managed to check for upward replication. We could add this back though, if we want to be even more careful. Doing it for the last 30 days might be a good idea actually:
|
|
Documentation is here: medic/medic-docs#63 |
garethbowen
left a comment
There was a problem hiding this comment.
Awesome work!
I've put some suggestions inline but no blockers so feel free to do them or not. I've approved this PR so you can go an merge without having to come back for another round.
| PURGE_INFO: function(progress) { | ||
| const n = progress.purged; | ||
| const percent = Math.floor((progress.processed / progress.total) * 100); | ||
| return `Cleaned ${n} documents (${percent}% complete)…`; |
There was a problem hiding this comment.
To make translation easier, perhaps do the calculation first, and call the translator with count and percent. Otherwise each language will have to do this calculation...
| const percent = Math.floor((progress.processed / progress.total) * 100); | ||
| return `Cleaned ${n} documents (${percent}% complete)…`; | ||
| }, | ||
| PURGE_AFTER: 'Optimising…', |
There was a problem hiding this comment.
Obviously these two keys need to be translated into all the languages we support. It might be difficult to get this done on short notice so feel free to raise an issue blocking the 3.4.0 release to get the translations for each language.
garethbowen
left a comment
There was a problem hiding this comment.
On second thoughts, I think we may need to handle the failure case more gracefully... comment inline.
|
@garethbowen OK check out 3f7a58c We no longer ever hard fail for anything. Instead, if the purge function cannot be compiled, or a purge set fails for some reason, we generate feedback errors (up to 10 to avoid spam), which are then generated into real feedback documents on successful Angular boot. Additionally, in testing I decided that it makes sense that purge should re-run if you change the purge function, so I added that as well. It's going to be an interesting decision when moving from client to server, but that's a conversation for another time. |
For your consideration.
I spent a couple of hours today knocking out the basics of purge on the phone:
Initiates a compaction if anything was purgedDoes nothing because we auto-compactI have tested it and it seems to nominally work.
Still to do:
More notes:
['id1', 'id2']->{id1: true, id2: ['role1', 'role2']}Interested in your thoughts.
#5048