From cd827b674a45643462205ca434544cf44ecd447d Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Mon, 24 Feb 2025 13:52:26 +0000 Subject: [PATCH] enhance: MemoCache.query returns {data, paths} just like denormalize --- packages/core/src/controller/Controller.ts | 8 +++++++- packages/normalizr/src/memo/MemoCache.ts | 10 ++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/core/src/controller/Controller.ts b/packages/core/src/controller/Controller.ts index b092e232b623..c3a5d77a0a92 100644 --- a/packages/core/src/controller/Controller.ts +++ b/packages/core/src/controller/Controller.ts @@ -545,7 +545,13 @@ export default class Controller< .slice(0, rest.length - 1) .map(ensurePojo) as SchemaArgs; - return this.memo.query(schema, args, state.entities as any, state.indexes); + const { data } = this.memo.query( + schema, + args, + state.entities as any, + state.indexes, + ); + return typeof data === 'symbol' ? undefined : (data as any); } private getSchemaResponse( diff --git a/packages/normalizr/src/memo/MemoCache.ts b/packages/normalizr/src/memo/MemoCache.ts index d0f570be05e4..4c72589c7963 100644 --- a/packages/normalizr/src/memo/MemoCache.ts +++ b/packages/normalizr/src/memo/MemoCache.ts @@ -69,15 +69,17 @@ export default class MemoCache { }, // NOTE: different orders can result in cache busting here; but since it's just a perf penalty we will allow for now argsKey: string = JSON.stringify(args), - ): DenormalizeNullable | undefined { + ): { + data: DenormalizeNullable | symbol; + paths: EntityPath[]; + } { const input = this.buildQueryKey(schema, args, entities, indexes, argsKey); if (!input) { - return; + return { data: undefined as any, paths: [] }; } - const { data } = this.denormalize(schema, input, entities, args); - return typeof data === 'symbol' ? undefined : (data as any); + return this.denormalize(schema, input, entities, args); } buildQueryKey(