Fix query cache (#7226)

This commit is contained in:
Denis Bykhov 2024-11-22 19:08:20 +05:00 committed by GitHub
parent c91e3c2554
commit fa8edd5d11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 10 deletions

View File

@ -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 {

View File

@ -1,5 +1,4 @@
import {
clone,
Hierarchy,
matchQuery,
toFindResult,
@ -59,14 +58,17 @@ export class Refs {
query: DocumentQuery<Doc>,
options?: FindOptions<T>
): FindResult<T> | null {
const classKey = _class + ':' + JSON.stringify(options?.lookup ?? {})
if (typeof query._id === 'string') {
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(clone([doc]), 1)
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)
}
}
}

View File

@ -128,8 +128,9 @@ export async function updateIssueRelation (
}
export async function getIssueIdByIdentifier (identifier: string): Promise<Ref<Issue> | 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
}