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 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('.')) { if (!key.includes('.')) {
try { try {
const attr = hierarchy.getAttribute(clazz, key) const attr = hierarchy.getAttribute(clazz, key)

View File

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