mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-18 16:31:57 +03:00
Fix query mixins (#7434)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
This commit is contained in:
parent
b0d1900172
commit
59b1635afb
@ -65,6 +65,10 @@ export function clone (obj: any, as?: (doc: any, m: any) => any, needAs?: (value
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeOf === 'Object') {
|
||||
const m = needAs?.(obj)
|
||||
return m !== undefined && as !== undefined ? as(result, m) : result
|
||||
}
|
||||
return result
|
||||
} else {
|
||||
return obj
|
||||
|
@ -27,6 +27,7 @@ import core, {
|
||||
IndexingUpdateEvent,
|
||||
Lookup,
|
||||
LookupData,
|
||||
Mixin,
|
||||
ModelDb,
|
||||
Ref,
|
||||
ReverseLookups,
|
||||
@ -150,6 +151,13 @@ export class LiveQuery implements WithTx, Client {
|
||||
}
|
||||
|
||||
private match (q: Query, doc: Doc, skipLookup = false): boolean {
|
||||
if (this.getHierarchy().isMixin(q._class)) {
|
||||
if (this.getHierarchy().hasMixin(doc, q._class)) {
|
||||
doc = this.getHierarchy().as(doc, q._class)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if (!this.getHierarchy().isDerived(doc._class, q._class)) {
|
||||
// Check if it is not a mixin and not match class
|
||||
const mixinClass = Hierarchy.mixinClass(doc)
|
||||
@ -518,20 +526,30 @@ export class LiveQuery implements WithTx, Client {
|
||||
return current
|
||||
}
|
||||
|
||||
private asMixin (doc: Doc, mixin: Ref<Mixin<Doc>>): Doc {
|
||||
if (this.getHierarchy().isMixin(mixin)) {
|
||||
return this.getHierarchy().as(doc, mixin)
|
||||
}
|
||||
return doc
|
||||
}
|
||||
|
||||
private async getCurrentDoc (
|
||||
q: Query,
|
||||
_id: Ref<Doc>,
|
||||
space: Ref<Space>,
|
||||
docCache: Map<string, Doc>
|
||||
): Promise<boolean> {
|
||||
const current = await this.getDocFromCache(docCache, _id, q._class, space, q)
|
||||
let current = await this.getDocFromCache(docCache, _id, q._class, space, q)
|
||||
if (q.result instanceof Promise) {
|
||||
q.result = await q.result
|
||||
}
|
||||
|
||||
const pos = q.result.findDoc(_id)
|
||||
if (current !== undefined) {
|
||||
current = this.asMixin(current, q._class)
|
||||
}
|
||||
if (current !== undefined && this.match(q, current)) {
|
||||
q.result.updateDoc(current)
|
||||
q.result.updateDoc(current, false)
|
||||
this.refs.updateDocuments(q, [current])
|
||||
} else {
|
||||
if (q.options?.limit === q.result.length) {
|
||||
@ -543,7 +561,6 @@ export class LiveQuery implements WithTx, Client {
|
||||
if (q.options?.total === true) {
|
||||
q.total--
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
@ -597,7 +614,7 @@ export class LiveQuery implements WithTx, Client {
|
||||
if (q.result instanceof Promise) {
|
||||
q.result = await q.result
|
||||
}
|
||||
const updatedDoc = q.result.findDoc(tx.objectId)
|
||||
let updatedDoc = q.result.findDoc(tx.objectId)
|
||||
if (updatedDoc !== undefined) {
|
||||
// If query contains search we must check use fulltext
|
||||
if (q.query.$search != null && q.query.$search.length > 0) {
|
||||
@ -608,6 +625,7 @@ export class LiveQuery implements WithTx, Client {
|
||||
} else {
|
||||
if (updatedDoc.modifiedOn < tx.modifiedOn) {
|
||||
await this.__updateMixinDoc(q, updatedDoc, tx)
|
||||
updatedDoc = this.asMixin(updatedDoc, q._class)
|
||||
const updateRefresh = this.checkUpdatedDocMatch(q, q.result, updatedDoc)
|
||||
if (updateRefresh) {
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user