diff --git a/packages/backend/src/misc/QuantumKVCache.ts b/packages/backend/src/misc/QuantumKVCache.ts index 72fae7b161..ebf4e2daa4 100644 --- a/packages/backend/src/misc/QuantumKVCache.ts +++ b/packages/backend/src/misc/QuantumKVCache.ts @@ -399,13 +399,15 @@ export class QuantumKVCache = Value> implements I /** * Gets multiple values from the local memory cache; returning undefined for any missing keys. * Returns cached data only - does not make any fetches. - * TODO don't return undefined, matching fetch */ @bindThis - public getMany(keys: Iterable): [key: string, value: T | undefined][] { - const results: [key: string, value: T | undefined][] = []; + public getMany(keys: Iterable): [key: string, value: T][] { + const results: [key: string, value: T][] = []; for (const key of keys) { - results.push([key, this.getMaybe(key)]); + const value = this.getMaybe(key); + if (value !== undefined) { + results.push([key, value]); + } } return results; } diff --git a/packages/backend/test/unit/misc/QuantumKVCacheTests.ts b/packages/backend/test/unit/misc/QuantumKVCacheTests.ts index 5d9428b6b7..a3d6abb3ad 100644 --- a/packages/backend/test/unit/misc/QuantumKVCacheTests.ts +++ b/packages/backend/test/unit/misc/QuantumKVCacheTests.ts @@ -308,7 +308,7 @@ describe(QuantumKVCache, () => { expect(result).toEqual([]); }); - it('should return the value for all keys', () => { + it('should include the value of all found keys', () => { const cache = makeCache(); cache.add('foo', 'bar'); cache.add('alpha', 'omega'); @@ -318,13 +318,13 @@ describe(QuantumKVCache, () => { expect(result).toEqual([['foo', 'bar'], ['alpha', 'omega']]); }); - it('should return undefined for missing keys', () => { + it('should exclude all missing keys', () => { const cache = makeCache(); cache.add('foo', 'bar'); const result = cache.getMany(['foo', 'alpha']); - expect(result).toEqual([['foo', 'bar'], ['alpha', undefined]]); + expect(result).toEqual([['foo', 'bar']]); }); });