Update debug logging

This commit is contained in:
Max Isom 2021-12-03 10:52:30 -05:00
parent 3f0f97f762
commit 4ffd679ddb
No known key found for this signature in database
GPG key ID: 25C9B1A7F6798880

View file

@ -87,16 +87,13 @@ export default class FileCacheProvider {
} }
private async evictOldestIfNecessary() { 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(); return this.evictionQueue.onEmpty();
} }
private async evictOldest() { private async evictOldest() {
debug('Evicting oldest (if found)'); debug('Evicting oldest files...');
const [{dataValues: {totalSizeBytes}}] = await FileCache.findAll({ const [{dataValues: {totalSizeBytes}}] = await FileCache.findAll({
attributes: [ attributes: [
[sequelize.fn('sum', sequelize.col('bytes')), 'totalSizeBytes'], [sequelize.fn('sum', sequelize.col('bytes')), 'totalSizeBytes'],
@ -113,14 +110,14 @@ export default class FileCacheProvider {
if (oldest) { if (oldest) {
await oldest.destroy(); await oldest.destroy();
await fs.unlink(path.join(this.config.CACHE_DIR, oldest.hash)); 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 // Continue to evict until we're under the limit
debug('Scheduling another eviction');
void this.evictionQueue.add(this.evictOldest.bind(this)); 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() { private async removeOrphans() {