LQ update doc update doc matched fix (#2101)

This commit is contained in:
Denis Bykhov 2022-06-18 14:10:48 +06:00 committed by GitHub
parent 5b534391b9
commit c412044ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 6 deletions

View File

@ -100,7 +100,10 @@ export function matchQuery<T extends Doc> (
return result
}
function checkMixinKey<T extends Doc> (key: string, clazz: Ref<Class<T>>, hierarchy: Hierarchy): string {
/**
* @public
*/
export function checkMixinKey<T extends Doc> (key: string, clazz: Ref<Class<T>>, hierarchy: Hierarchy): string {
if (!key.includes('.')) {
try {
const attr = hierarchy.getAttribute(clazz, key)

View File

@ -42,7 +42,9 @@ import core, {
TxResult,
TxUpdateDoc,
WithLookup,
toFindResult
toFindResult,
checkMixinKey,
matchQuery
} from '@anticrm/core'
import { deepEqual } from 'fast-equals'
@ -367,8 +369,9 @@ export class LiveQuery extends TxProcessor implements Client {
}
this.sort(q, tx)
await this.updatedDocCallback(q.result[pos], q)
} else if (this.matchQuery(q, tx)) {
return await this.refresh(q)
} else if (await this.matchQuery(q, tx)) {
this.sort(q, tx)
await this.updatedDocCallback(q.result[pos], q)
}
await this.handleDocUpdateLookup(q, tx)
}
@ -431,7 +434,7 @@ export class LiveQuery extends TxProcessor implements Client {
}
// Check if query is partially matched.
private matchQuery (q: Query, tx: TxUpdateDoc<Doc>): boolean {
private async matchQuery (q: Query, tx: TxUpdateDoc<Doc>): Promise<boolean> {
if (!this.client.getHierarchy().isDerived(tx.objectClass, q._class)) {
return false
}
@ -446,10 +449,28 @@ export class LiveQuery extends TxProcessor implements Client {
TxProcessor.updateDoc2Doc(doc, tx)
let matched = false
for (const key in q.query) {
const value = (q.query as any)[key]
const res = findProperty([doc], key, value)
const tkey = checkMixinKey(key, q._class, this.client.getHierarchy())
if ((doc as any)[tkey] === undefined) continue
const res = findProperty([doc], tkey, value)
if (res.length === 0) {
return false
} else {
matched = true
}
}
if (matched) {
const realDoc = await this.client.findOne(q._class, { _id: doc._id }, q.options)
if (realDoc === undefined) return false
const res = matchQuery([realDoc], q.query, q._class, this.client.getHierarchy())
if (res.length === 1) {
if (q.result instanceof Promise) {
q.result = await q.result
}
q.result.push(res[0])
return true
}
}