From 977d4ec3430aaa69ccac6f161dee180620190795 Mon Sep 17 00:00:00 2001 From: Bastian Rihm Date: Tue, 14 Nov 2023 11:14:00 +0100 Subject: [PATCH 1/2] Synchronize commitUpdate --- .../app/gateways/repositories/base-repository.ts | 15 +++++++++++++-- .../services/data-store-update-manager.service.ts | 6 ++++-- .../services/view-model-store-update.service.ts | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/client/src/app/gateways/repositories/base-repository.ts b/client/src/app/gateways/repositories/base-repository.ts index 797066f1d9..79d5f02650 100644 --- a/client/src/app/gateways/repositories/base-repository.ts +++ b/client/src/app/gateways/repositories/base-repository.ts @@ -3,6 +3,7 @@ import { auditTime, BehaviorSubject, filter, Observable, Subject, Subscription } import { HasSequentialNumber, Identifiable } from 'src/app/domain/interfaces'; import { OnAfterAppsLoaded } from 'src/app/infrastructure/definitions/hooks/after-apps-loaded'; import { ListUpdateData } from 'src/app/infrastructure/utils'; +import { Deferred } from 'src/app/infrastructure/utils/promises'; import { OsSortProperty } from 'src/app/site/base/base-sort.service'; import { SortListService } from 'src/app/ui/modules/list'; @@ -40,6 +41,7 @@ enum PipelineActionType { interface UpdatePipelineAction { funct: () => Promise; type: PipelineActionType; + defer?: Deferred; key?: string; } @@ -319,7 +321,8 @@ export abstract class BaseRepository[]): void { + public changedModels(ids: Id[], changedModels: BaseModel[]): Promise { + const defer = new Deferred(); this.pushToPipeline({ funct: async () => { const newViewModels: V[] = []; @@ -344,9 +347,11 @@ export abstract class BaseRepository { if (!this.currentUpdateSlot || !this.currentUpdateSlot.equal(slot)) { throw new Error(`No or wrong update slot to be finished!`); } @@ -174,6 +174,7 @@ export class DataStoreUpdateManagerService { // notify repositories in two phases const repositories = this.mapperService.getAllRepositories(); + const modelUpdates = []; // Phase 1: deleting and creating of view models (in this order) for (const repo of repositories) { @@ -184,10 +185,11 @@ export class DataStoreUpdateManagerService { const changedModelIds = slot.getChangedModelIdsForCollection(repo.collection); if (changedModelIds?.length) { - repo.changedModels(changedModelIds, changedModels[repo.COLLECTION]); + modelUpdates.push(repo.changedModels(changedModelIds, changedModels[repo.COLLECTION])); } } + await Promise.all(modelUpdates); // Phase 2: updating all repositories for (const repo of repositories) { repo.commitUpdate(slot.getAllModelsIdsForCollection(repo.collection)); diff --git a/client/src/app/site/services/view-model-store-update.service.ts b/client/src/app/site/services/view-model-store-update.service.ts index 62a978973b..f9665c64b7 100644 --- a/client/src/app/site/services/view-model-store-update.service.ts +++ b/client/src/app/site/services/view-model-store-update.service.ts @@ -125,7 +125,7 @@ export class ViewModelStoreUpdateService { await this.DS.addOrUpdate(changedModels[collection]); } - this.DSUpdateService.commit(updateSlot, changedModels); + await this.DSUpdateService.commit(updateSlot, changedModels); } /** From bd1db83038c13e168219dfb8041e806c8a74a058 Mon Sep 17 00:00:00 2001 From: Bastian Rihm Date: Tue, 14 Nov 2023 11:30:45 +0100 Subject: [PATCH 2/2] Cleanup --- .../src/app/site/services/data-store-update-manager.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/app/site/services/data-store-update-manager.service.ts b/client/src/app/site/services/data-store-update-manager.service.ts index 19eb9b22ff..19a7cdd778 100644 --- a/client/src/app/site/services/data-store-update-manager.service.ts +++ b/client/src/app/site/services/data-store-update-manager.service.ts @@ -188,8 +188,8 @@ export class DataStoreUpdateManagerService { modelUpdates.push(repo.changedModels(changedModelIds, changedModels[repo.COLLECTION])); } } - await Promise.all(modelUpdates); + // Phase 2: updating all repositories for (const repo of repositories) { repo.commitUpdate(slot.getAllModelsIdsForCollection(repo.collection));