mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-19 17:01: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
|
return result
|
||||||
} else {
|
} else {
|
||||||
return obj
|
return obj
|
||||||
|
@ -27,6 +27,7 @@ import core, {
|
|||||||
IndexingUpdateEvent,
|
IndexingUpdateEvent,
|
||||||
Lookup,
|
Lookup,
|
||||||
LookupData,
|
LookupData,
|
||||||
|
Mixin,
|
||||||
ModelDb,
|
ModelDb,
|
||||||
Ref,
|
Ref,
|
||||||
ReverseLookups,
|
ReverseLookups,
|
||||||
@ -150,6 +151,13 @@ export class LiveQuery implements WithTx, Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private match (q: Query, doc: Doc, skipLookup = false): boolean {
|
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)) {
|
if (!this.getHierarchy().isDerived(doc._class, q._class)) {
|
||||||
// Check if it is not a mixin and not match class
|
// Check if it is not a mixin and not match class
|
||||||
const mixinClass = Hierarchy.mixinClass(doc)
|
const mixinClass = Hierarchy.mixinClass(doc)
|
||||||
@ -518,20 +526,30 @@ export class LiveQuery implements WithTx, Client {
|
|||||||
return current
|
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 (
|
private async getCurrentDoc (
|
||||||
q: Query,
|
q: Query,
|
||||||
_id: Ref<Doc>,
|
_id: Ref<Doc>,
|
||||||
space: Ref<Space>,
|
space: Ref<Space>,
|
||||||
docCache: Map<string, Doc>
|
docCache: Map<string, Doc>
|
||||||
): Promise<boolean> {
|
): 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) {
|
if (q.result instanceof Promise) {
|
||||||
q.result = await q.result
|
q.result = await q.result
|
||||||
}
|
}
|
||||||
|
|
||||||
const pos = q.result.findDoc(_id)
|
const pos = q.result.findDoc(_id)
|
||||||
|
if (current !== undefined) {
|
||||||
|
current = this.asMixin(current, q._class)
|
||||||
|
}
|
||||||
if (current !== undefined && this.match(q, current)) {
|
if (current !== undefined && this.match(q, current)) {
|
||||||
q.result.updateDoc(current)
|
q.result.updateDoc(current, false)
|
||||||
this.refs.updateDocuments(q, [current])
|
this.refs.updateDocuments(q, [current])
|
||||||
} else {
|
} else {
|
||||||
if (q.options?.limit === q.result.length) {
|
if (q.options?.limit === q.result.length) {
|
||||||
@ -543,7 +561,6 @@ export class LiveQuery implements WithTx, Client {
|
|||||||
if (q.options?.total === true) {
|
if (q.options?.total === true) {
|
||||||
q.total--
|
q.total--
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -597,7 +614,7 @@ export class LiveQuery implements WithTx, Client {
|
|||||||
if (q.result instanceof Promise) {
|
if (q.result instanceof Promise) {
|
||||||
q.result = await q.result
|
q.result = await q.result
|
||||||
}
|
}
|
||||||
const updatedDoc = q.result.findDoc(tx.objectId)
|
let updatedDoc = q.result.findDoc(tx.objectId)
|
||||||
if (updatedDoc !== undefined) {
|
if (updatedDoc !== undefined) {
|
||||||
// If query contains search we must check use fulltext
|
// If query contains search we must check use fulltext
|
||||||
if (q.query.$search != null && q.query.$search.length > 0) {
|
if (q.query.$search != null && q.query.$search.length > 0) {
|
||||||
@ -608,6 +625,7 @@ export class LiveQuery implements WithTx, Client {
|
|||||||
} else {
|
} else {
|
||||||
if (updatedDoc.modifiedOn < tx.modifiedOn) {
|
if (updatedDoc.modifiedOn < tx.modifiedOn) {
|
||||||
await this.__updateMixinDoc(q, updatedDoc, tx)
|
await this.__updateMixinDoc(q, updatedDoc, tx)
|
||||||
|
updatedDoc = this.asMixin(updatedDoc, q._class)
|
||||||
const updateRefresh = this.checkUpdatedDocMatch(q, q.result, updatedDoc)
|
const updateRefresh = this.checkUpdatedDocMatch(q, q.result, updatedDoc)
|
||||||
if (updateRefresh) {
|
if (updateRefresh) {
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user