mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-28 19:25:36 +00:00
UBERF-4649: Fix query projection/cache issue (#4200)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
810ec9010b
commit
58b841518a
@ -510,7 +510,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async txUpdateDoc (tx: TxUpdateDoc<Doc>): Promise<TxResult> {
|
protected async txUpdateDoc (tx: TxUpdateDoc<Doc>): Promise<TxResult> {
|
||||||
const docCache = new Map<Ref<Doc>, Doc>()
|
const docCache = new Map<string, Doc>()
|
||||||
for (const queries of this.queries) {
|
for (const queries of this.queries) {
|
||||||
const isTx = this.client.getHierarchy().isDerived(queries[0], core.class.Tx)
|
const isTx = this.client.getHierarchy().isDerived(queries[0], core.class.Tx)
|
||||||
for (const q of queries[1]) {
|
for (const q of queries[1]) {
|
||||||
@ -525,7 +525,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleDocUpdate (q: Query, tx: TxUpdateDoc<Doc>, docCache?: Map<Ref<Doc>, Doc>): Promise<void> {
|
private async handleDocUpdate (q: Query, tx: TxUpdateDoc<Doc>, docCache?: Map<string, Doc>): Promise<void> {
|
||||||
if (q.result instanceof Promise) {
|
if (q.result instanceof Promise) {
|
||||||
q.result = await q.result
|
q.result = await q.result
|
||||||
}
|
}
|
||||||
@ -658,7 +658,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if query is partially matched.
|
// Check if query is partially matched.
|
||||||
private async matchQuery (q: Query, tx: TxUpdateDoc<Doc>, docCache?: Map<Ref<Doc>, Doc>): Promise<boolean> {
|
private async matchQuery (q: Query, tx: TxUpdateDoc<Doc>, docCache?: Map<string, 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
|
||||||
}
|
}
|
||||||
@ -687,10 +687,15 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (matched) {
|
if (matched) {
|
||||||
const realDoc = docCache?.get(doc._id) ?? (await this.client.findOne(q._class, { _id: doc._id }, q.options))
|
const docIdKey = doc._id + JSON.stringify(q.options?.lookup)
|
||||||
|
|
||||||
|
const lookup = q.options?.lookup
|
||||||
|
const realDoc =
|
||||||
|
docCache?.get(docIdKey) ??
|
||||||
|
(await this.client.findOne(q._class, { _id: doc._id }, lookup !== undefined ? { lookup } : undefined))
|
||||||
|
|
||||||
if (realDoc != null && docCache != null) {
|
if (realDoc != null && docCache != null) {
|
||||||
docCache?.set(realDoc._id, realDoc)
|
docCache?.set(docIdKey, realDoc)
|
||||||
}
|
}
|
||||||
if (realDoc === undefined) return false
|
if (realDoc === undefined) return false
|
||||||
const res = matchQuery([realDoc], q.query, q._class, this.client.getHierarchy())
|
const res = matchQuery([realDoc], q.query, q._class, this.client.getHierarchy())
|
||||||
|
Loading…
Reference in New Issue
Block a user