diff --git a/src/Utils/auth-utils.ts b/src/Utils/auth-utils.ts index 006eb8d..a4f2e73 100644 --- a/src/Utils/auth-utils.ts +++ b/src/Utils/auth-utils.ts @@ -97,15 +97,21 @@ export const addTransactionCapability = ( * prefetches some data and stores in memory, * useful if these data points will be used together often * */ - const prefetch = async(type: keyof SignalDataTypeMap, ids: string[]) => { + const prefetch = async(type: T, ids: string[]) => { const dict = transactionCache[type] - const idsRequiringFetch = dict ? ids.filter(item => !(item in dict)) : ids + const idsRequiringFetch = dict + ? ids.filter(item => typeof dict[item] !== 'undefined') + : ids // only fetch if there are any items to fetch if(idsRequiringFetch.length) { dbQueriesInTransaction += 1 const result = await state.get(type, idsRequiringFetch) - transactionCache[type] = Object.assign(transactionCache[type] || { }, result) + transactionCache[type] ||= {} + transactionCache[type] = Object.assign( + transactionCache[type]!, + result + ) } }