From 643bddf44ef93df7b67f0b33598435c51fa0c42e Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 24 Oct 2021 11:37:16 +0100 Subject: [PATCH] Added comments --- packages/server/src/models/ChangeModel.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/server/src/models/ChangeModel.ts b/packages/server/src/models/ChangeModel.ts index 1c78f0780de..0e66bffe6e4 100644 --- a/packages/server/src/models/ChangeModel.ts +++ b/packages/server/src/models/ChangeModel.ts @@ -327,6 +327,11 @@ export default class ChangeModel extends BaseModel { logger.info(`deleteOldChanges: Processing changes older than: ${formatDateTime(cutOffDate)} (${cutOffDate})`); while (true) { + // First get all the UPDATE changes before the specified date, and + // order by the items that had the most changes. Also for each item + // get the most recent change date from within that time interval, + // as we need this below. + const changeReport: ChangeReportItem[] = await this .db(this.tableName) @@ -354,6 +359,9 @@ export default class ChangeModel extends BaseModel { return; } + // Still from within the specified interval, delete all + // UPDATE changes, except for the most recent one. + const deletedCount = await this .db(this.tableName) .where('type', '=', ChangeType.Update) @@ -367,12 +375,12 @@ export default class ChangeModel extends BaseModel { } }, 'ChangeModel::deleteOldChanges'); - logger.info(`deleteOldChanges: Processed: ${doneItemIds.length} items. Deleted: ${totalDeletedCount}`); + logger.info(`deleteOldChanges: Processed: ${doneItemIds.length} items. Deleted: ${totalDeletedCount} changes.`); if (error) throw error; } - logger.info(`deleteOldChanges: Finished processing. Done ${doneItemIds.length} items. Deleted: ${totalDeletedCount}`); + logger.info(`deleteOldChanges: Finished processing. Done ${doneItemIds.length} items. Deleted: ${totalDeletedCount} changes.`); } public async save(change: Change, options: SaveOptions = {}): Promise {