Skip to content

Commit 0cc46ac

Browse files
liz709dfahlander
authored andcommitted
perf(live-query): avoid redundant double deepClone on initial query cache populate
1 parent fb5d3b7 commit 0cc46ac

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/live-query/cache/cache-middleware.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,12 @@ export const cacheMiddleware: Middleware<DBCore> = {
292292
Object.freeze(result[i]);
293293
}
294294
Object.freeze(result);
295-
} else {
296-
// If not frozen, we need to clone the result to avoid user mutating the cache
297-
// When we do this, user's must feel conformable with the fact that the result
298-
// can be mutated deeply - user is not expected to have any respect for immutability.
299-
res.result = deepClone(result);
300295
}
296+
// If not frozen (cache: 'cloned'), we do NOT clone here.
297+
// Since every cache read (including the initial one) will go through
298+
// the downstream .then() handler and perform a deepClone on read,
299+
// the original query results in the cache remain perfectly isolated
300+
// and we avoid a redundant double deepClone on the first query.
301301
return res;
302302
})
303303
.catch((error) => {

0 commit comments

Comments
 (0)