mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-20 07:10:02 +00:00
LQ update doc update doc matched fix (#2101)
This commit is contained in:
parent
5b534391b9
commit
c412044ea6
@ -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)
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user