Refactor cache entry removal to use Set for removalQueue

60e4993a89936288007034406221b4292f7be940

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +5 -5Showing whitespace changes
src/endpoints/characters.js+5 -5
@@ -50,7 +50,7 @@ const diskCache = {
50 */50 */
51 _removeCacheEntries: async function() {51 _removeCacheEntries: async function() {
52 try {52 try {
53 if (!useDiskCache || this.removalQueue.length === 0) {53 if (!useDiskCache || this.removalQueue.size === 0) {
54 return;54 return;
55 }55 }
5656
@@ -62,7 +62,7 @@ const diskCache = {
62 }62 }
63 }63 }
64 console.info('Removed cache entries:', this.removalQueue);64 console.info('Removed cache entries:', this.removalQueue);
65 this.removalQueue = [];65 this.removalQueue.clear();
66 } catch (error) {66 } catch (error) {
67 console.error('Error while removing cache entries:', error);67 console.error('Error while removing cache entries:', error);
68 }68 }
@@ -84,9 +84,9 @@ const diskCache = {
84 },84 },
85 /**85 /**
86 * Queue for removal of cache entries.86 * Queue for removal of cache entries.
87 * @type {string[]}87 * @type {Set<string>}
88 */88 */
89 removalQueue: [],89 removalQueue: new Set(),
90};90};
9191
92/**92/**
@@ -166,7 +166,7 @@ async function writeCharacterData(inputFile, data, outputFile, request, crop = u
166 }166 }
167 }167 }
168 if (useDiskCache && !Buffer.isBuffer(inputFile)) {168 if (useDiskCache && !Buffer.isBuffer(inputFile)) {
169 diskCache.removalQueue.push(inputFile);169 diskCache.removalQueue.add(inputFile);
170 }170 }
171 /**171 /**
172 * Read the image, resize, and save it as a PNG into the buffer.172 * Read the image, resize, and save it as a PNG into the buffer.