From 876d0e3ebe0265901db7ff378798c46d24b26db0 Mon Sep 17 00:00:00 2001 From: Alexey Nalivaiko Date: Wed, 17 Apr 2019 17:33:03 +0300 Subject: [PATCH] [AMSA-chore] hotfix sync history stats --- src/core/sync-apps/sync-stats.ts | 25 +++++++++++++++---------- src/core/sync-apps/sync.ts | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/core/sync-apps/sync-stats.ts b/src/core/sync-apps/sync-stats.ts index 1d8deff..e96b024 100644 --- a/src/core/sync-apps/sync-stats.ts +++ b/src/core/sync-apps/sync-stats.ts @@ -27,10 +27,10 @@ export interface SyncInfo { export class SyncStats { public readonly affectedApps = { - created: [], - updated: [], - deleted: [], - withErrors: [] + created: new Map(), + updated: new Map(), + deleted: new Map(), + withErrors: new Map() }; public id: string; @@ -52,22 +52,22 @@ export class SyncStats { } appCreated (app: AppodealApp) { - this.affectedApps.created.push(app); + this.affectedApps.created.set(app.id, app); } appUpdated (app: AppodealApp) { - if (this.affectedApps.created.some(v => v.id === app.id)) { + if (this.affectedApps.created.has(app.id)) { return; } - this.affectedApps.updated.push(app); + this.affectedApps.updated.set(app.id, app); } appDeleted (app: AppodealApp) { - this.affectedApps.deleted.push(app); + this.affectedApps.deleted.set(app.id, app); } errorWhileSync (app: AppodealApp) { - this.affectedApps.withErrors.push(app); + this.affectedApps.withErrors.set(app.id, app); } toPlainObject (): SyncInfo { @@ -75,7 +75,12 @@ export class SyncStats { id: this.sync.id, runner: this.sync.runner, hasErrors: this.sync.hasErrors, - affectedApps: this.affectedApps, + affectedApps: { + created: [...this.affectedApps.created.values()], + updated: [...this.affectedApps.updated.values()], + deleted: [...this.affectedApps.deleted.values()], + withErrors: [...this.affectedApps.withErrors.values()] + }, startTs: this.startTs, endTs: this.endTs, terminated: this.terminated, diff --git a/src/core/sync-apps/sync.ts b/src/core/sync-apps/sync.ts index 976c269..5e24e13 100644 --- a/src/core/sync-apps/sync.ts +++ b/src/core/sync-apps/sync.ts @@ -256,6 +256,7 @@ export class Sync { const adUnitsToDelete = this.getActiveAdmobAdUnitsCreatedByApp(app, adMobApp).map(adUnit => adUnit.adUnitId); if (adUnitsToDelete.length) { await this.deleteAdMobAdUnits(adUnitsToDelete); + this.context.removeAdMobAdUnits(adUnitsToDelete); this.stats.appDeleted(app); yield `${adUnitsToDelete.length} adUnits deleted`; } else {