Skip to content

Commit 9c7853f

Browse files
committed
refactor: compute deletionStartTimestamp and deletionCutoffTimestamp as the first thing
1 parent 3eab205 commit 9c7853f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/mongodb-log-writer/src/mongo-log-manager.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export class MongoLogManager {
6363

6464
/** Clean up log files older than `retentionDays`. */
6565
async cleanupOldLogFiles(maxDurationMs = 5_000, remainingRetries = 1): Promise<void> {
66+
const deletionStartTimestamp = Date.now();
67+
// Delete files older than N days
68+
const deletionCutoffTimestamp =
69+
deletionStartTimestamp - this._options.retentionDays * 86400 * 1000;
70+
6671
const dir = this._options.directory;
6772
let dirHandle;
6873
try {
@@ -71,10 +76,6 @@ export class MongoLogManager {
7176
return;
7277
}
7378

74-
const deletionStartTimestamp = Date.now();
75-
// Delete files older than N days
76-
const deletionCutoffTimestamp =
77-
deletionStartTimestamp - this._options.retentionDays * 86400 * 1000;
7879
// Store the known set of least recent files in a heap in order to be able to
7980
// delete all but the most recent N files.
8081
const leastRecentFileHeap = new Heap<{

0 commit comments

Comments
 (0)