From fa8edd5d11d03d5a725015f20b56f26d2755fb78 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Fri, 22 Nov 2024 19:08:20 +0500 Subject: [PATCH] Fix query cache (#7226) --- packages/query/src/index.ts | 2 ++ packages/query/src/refs.ts | 21 ++++++++++++--------- plugins/tracker-resources/src/issues.ts | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 6977f58a0c..964f67251d 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -997,6 +997,8 @@ export class LiveQuery implements WithTx, Client { const result = q.result + this.refs.updateDocuments(q, result.getDocs()) + if (bulkUpdate) { this.queriesToUpdate.set(q.id, q) } else { diff --git a/packages/query/src/refs.ts b/packages/query/src/refs.ts index ae22a3f073..173539bdd5 100644 --- a/packages/query/src/refs.ts +++ b/packages/query/src/refs.ts @@ -1,5 +1,4 @@ import { - clone, Hierarchy, matchQuery, toFindResult, @@ -59,14 +58,17 @@ export class Refs { query: DocumentQuery, options?: FindOptions ): FindResult | null { - const classKey = _class + ':' + JSON.stringify(options?.lookup ?? {}) if (typeof query._id === 'string') { - // One document query - const doc = this.documentRefs.get(classKey)?.get(query._id)?.doc - if (doc !== undefined) { - const q = matchQuery([doc], query, _class, this.getHierarchy()) - if (q.length > 0) { - return toFindResult(clone([doc]), 1) + const desc = this.getHierarchy().getDescendants(_class) + for (const des of desc) { + const classKey = des + ':' + JSON.stringify(options?.lookup ?? {}) + // One document query + const doc = this.documentRefs.get(classKey)?.get(query._id)?.doc + if (doc !== undefined) { + const q = matchQuery([doc], query, _class, this.getHierarchy()) + if (q.length > 0) { + return toFindResult(this.getHierarchy().clone([doc]), 1) + } } } } @@ -76,13 +78,14 @@ export class Refs { options?.sort === undefined && options?.projection === undefined ) { + const classKey = _class + ':' + JSON.stringify(options?.lookup ?? {}) const docs = this.documentRefs.get(classKey) if (docs !== undefined) { const _docs = Array.from(docs.values()).map((it) => it.doc) const q = matchQuery(_docs, query, _class, this.getHierarchy()) if (q.length > 0) { - return toFindResult(clone([q[0]]), 1) + return toFindResult(this.getHierarchy().clone([q[0]]), 1) } } } diff --git a/plugins/tracker-resources/src/issues.ts b/plugins/tracker-resources/src/issues.ts index 88cd4c9571..bf4093a665 100644 --- a/plugins/tracker-resources/src/issues.ts +++ b/plugins/tracker-resources/src/issues.ts @@ -128,8 +128,9 @@ export async function updateIssueRelation ( } export async function getIssueIdByIdentifier (identifier: string): Promise | undefined> { + if (!isIssueId(identifier)) return const client = getClient() - const issue = await client.findOne(tracker.class.Issue, { identifier }, { projection: { _id: 1 } }) + const issue = await client.findOne(tracker.class.Issue, { identifier }) return issue?._id }