[web-db] improve persisting lifecycle
Summary:
Previous version with _throttle might cause problems when persisting will be longer than 300ms (thanks @tomek for identifying).
Change previous approach to the following algorithm:
- If there was a write operation and there is no ongoing persisting process (persistInProgress: false) - start persisting
- If there was a write operation and there is an ongoing persisting process - mark that it will need to be restarted (set persistNeeded: true).
- If persisting process finishes and there was a write operation (persistNeeded: true) - start it again and mark that it no longer needs to be restarted (persistNeeded: false)
- If persisting process finishes and there was no write operation - finish and mark that there is no ongoing persisting process (persistInProgress: false)
- Each time persisting process is starting set persistInProgress: true
Depends on D7288
Test Plan:
- Test if persistence works
- Add sleep and check if it works for long persistence
Reviewers: michal, tomek
Reviewed By: tomek
Subscribers: ashoat, atul, tomek
Differential Revision: https://phab.comm.dev/D7289