Fix initializing cache with batch ids for the first time

For each group we record the last batch we processed so that we can
download events since that batch and update the cache. Unfortunately
we would only write those ids when some events are processed. In case
there are no events we would not download any batches on next login.

This fixes plugs the issue with this case by preemptively writing last
id if none could be loaded. Next time we will download batches starting
with that id.
This commit is contained in:
ivk 2022-03-01 16:19:18 +01:00 committed by Ivan Kupalov
parent b2a01f5164
commit d572734d87
4 changed files with 24 additions and 4 deletions

View file

@ -44,6 +44,13 @@ export interface IEntityRestCache extends EntityRestInterface {
*/
getLastEntityEventBatchForGroup(groupId: Id): Promise<Id | null>;
/**
* Saved tha batch id of the most recently processed batch manually.
*
* Is needed when the cache is new but we want to make sure that the next time we will download from this moment, even if we don't receive any events.
*/
setLastEntityEventBatchForGroup(groupId: Id, batchId: Id): Promise<void>;
/**
* Persist the last time client downloaded event batches. This is not the last *processed* item, merely when things were *downloaded*. We use it to
* detect out-of-sync.
@ -198,6 +205,10 @@ export class EntityRestCache implements IEntityRestCache {
return this.storage.getLastBatchIdForGroup(groupId)
}
setLastEntityEventBatchForGroup(groupId: Id, batchId: Id): Promise<void> {
return this.storage.putLastBatchIdForGroup(groupId, batchId)
}
purgeStorage(): Promise<void> {
return this.storage.purgeStorage()
}