From 4ffd679ddb227ea6e6ac911de382e4d5bec0926d Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 3 Dec 2021 10:52:30 -0500 Subject: [PATCH] Update debug logging --- src/services/file-cache.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index e82b705..7e7aa6d 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -87,16 +87,13 @@ export default class FileCacheProvider { } private async evictOldestIfNecessary() { - if (this.evictionQueue.size === 0 && this.evictionQueue.pending === 0) { - debug('Adding evictOldest task to queue'); - void this.evictionQueue.add(this.evictOldest.bind(this)); - } + void this.evictionQueue.add(this.evictOldest.bind(this)); return this.evictionQueue.onEmpty(); } private async evictOldest() { - debug('Evicting oldest (if found)'); + debug('Evicting oldest files...'); const [{dataValues: {totalSizeBytes}}] = await FileCache.findAll({ attributes: [ [sequelize.fn('sum', sequelize.col('bytes')), 'totalSizeBytes'], @@ -113,14 +110,14 @@ export default class FileCacheProvider { if (oldest) { await oldest.destroy(); await fs.unlink(path.join(this.config.CACHE_DIR, oldest.hash)); + debug(`${oldest.hash} has been evicted`); } // Continue to evict until we're under the limit - debug('Scheduling another eviction'); void this.evictionQueue.add(this.evictOldest.bind(this)); + } else { + debug(`No files needed to be evicted. Total size of the cache is currently ${totalSizeBytes} bytes, and the cache limit is ${this.config.CACHE_LIMIT_IN_BYTES} bytes.`); } - - debug('Finished evictOldest'); } private async removeOrphans() {