mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-19 14:55:31 +00:00
UBERF-7247: Fix queryFind for mixins on server (#5803)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
74e8948421
commit
a596f468ea
@ -13,7 +13,20 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
import type { Account, Arr, Class, Data, Doc, Domain, Mixin, Obj, Ref, TxCreateDoc, TxCUD } from '@hcengineering/core'
|
import type {
|
||||||
|
Account,
|
||||||
|
Arr,
|
||||||
|
Class,
|
||||||
|
Data,
|
||||||
|
Doc,
|
||||||
|
Domain,
|
||||||
|
Mixin,
|
||||||
|
Obj,
|
||||||
|
Ref,
|
||||||
|
Space,
|
||||||
|
TxCreateDoc,
|
||||||
|
TxCUD
|
||||||
|
} from '@hcengineering/core'
|
||||||
import core, { AccountRole, AttachedDoc, ClassifierKind, DOMAIN_MODEL, DOMAIN_TX, TxFactory } from '@hcengineering/core'
|
import core, { AccountRole, AttachedDoc, ClassifierKind, DOMAIN_MODEL, DOMAIN_TX, TxFactory } from '@hcengineering/core'
|
||||||
import type { IntlString, Plugin } from '@hcengineering/platform'
|
import type { IntlString, Plugin } from '@hcengineering/platform'
|
||||||
import { plugin } from '@hcengineering/platform'
|
import { plugin } from '@hcengineering/platform'
|
||||||
@ -54,16 +67,26 @@ export interface AttachedComment extends AttachedDoc {
|
|||||||
message: string
|
message: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TestProject extends Space {
|
||||||
|
prjName: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TestProjectMixin extends TestProject {
|
||||||
|
someField?: string
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export const test = plugin('test' as Plugin, {
|
export const test = plugin('test' as Plugin, {
|
||||||
mixin: {
|
mixin: {
|
||||||
TestMixin: '' as Ref<Mixin<TestMixin>>
|
TestMixin: '' as Ref<Mixin<TestMixin>>,
|
||||||
|
TestProjectMixin: '' as Ref<Mixin<TestProjectMixin>>
|
||||||
},
|
},
|
||||||
class: {
|
class: {
|
||||||
TestComment: '' as Ref<Class<AttachedComment>>,
|
TestComment: '' as Ref<Class<AttachedComment>>,
|
||||||
ParticipantsHolder: '' as Ref<Class<ParticipantsHolder>>
|
ParticipantsHolder: '' as Ref<Class<ParticipantsHolder>>,
|
||||||
|
TestProject: '' as Ref<Class<TestProject>>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -88,13 +111,6 @@ export function genMinModel (): TxCUD<Doc>[] {
|
|||||||
txes.push(
|
txes.push(
|
||||||
createClass(core.class.Doc, { label: 'Doc' as IntlString, extends: core.class.Obj, kind: ClassifierKind.CLASS })
|
createClass(core.class.Doc, { label: 'Doc' as IntlString, extends: core.class.Obj, kind: ClassifierKind.CLASS })
|
||||||
)
|
)
|
||||||
txes.push(
|
|
||||||
createClass(core.class.AttachedDoc, {
|
|
||||||
label: 'AttachedDoc' as IntlString,
|
|
||||||
extends: core.class.Doc,
|
|
||||||
kind: ClassifierKind.MIXIN
|
|
||||||
})
|
|
||||||
)
|
|
||||||
txes.push(
|
txes.push(
|
||||||
createClass(core.class.Class, {
|
createClass(core.class.Class, {
|
||||||
label: 'Class' as IntlString,
|
label: 'Class' as IntlString,
|
||||||
@ -103,6 +119,21 @@ export function genMinModel (): TxCUD<Doc>[] {
|
|||||||
domain: DOMAIN_MODEL
|
domain: DOMAIN_MODEL
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
txes.push(
|
||||||
|
createClass(core.class.Mixin, {
|
||||||
|
label: 'Mixin' as IntlString,
|
||||||
|
extends: core.class.Class,
|
||||||
|
kind: ClassifierKind.CLASS,
|
||||||
|
domain: DOMAIN_MODEL
|
||||||
|
})
|
||||||
|
)
|
||||||
|
txes.push(
|
||||||
|
createClass(core.class.AttachedDoc, {
|
||||||
|
label: 'AttachedDoc' as IntlString,
|
||||||
|
extends: core.class.Doc,
|
||||||
|
kind: ClassifierKind.MIXIN
|
||||||
|
})
|
||||||
|
)
|
||||||
txes.push(
|
txes.push(
|
||||||
createClass(core.class.Space, {
|
createClass(core.class.Space, {
|
||||||
label: 'Space' as IntlString,
|
label: 'Space' as IntlString,
|
||||||
@ -164,6 +195,13 @@ export function genMinModel (): TxCUD<Doc>[] {
|
|||||||
kind: ClassifierKind.CLASS
|
kind: ClassifierKind.CLASS
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
txes.push(
|
||||||
|
createClass(core.class.TxMixin, {
|
||||||
|
label: 'TxMixin' as IntlString,
|
||||||
|
extends: core.class.TxCUD,
|
||||||
|
kind: ClassifierKind.CLASS
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
txes.push(
|
txes.push(
|
||||||
createClass(test.mixin.TestMixin, {
|
createClass(test.mixin.TestMixin, {
|
||||||
@ -173,6 +211,23 @@ export function genMinModel (): TxCUD<Doc>[] {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
txes.push(
|
||||||
|
createClass(test.class.TestProject, {
|
||||||
|
label: 'TestProject' as IntlString,
|
||||||
|
extends: core.class.Space,
|
||||||
|
kind: ClassifierKind.CLASS,
|
||||||
|
domain: DOMAIN_TEST
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
txes.push(
|
||||||
|
createClass(test.mixin.TestProjectMixin, {
|
||||||
|
label: 'TestProjectMixin' as IntlString,
|
||||||
|
extends: test.class.TestProject,
|
||||||
|
kind: ClassifierKind.MIXIN
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
txes.push(
|
txes.push(
|
||||||
createClass(test.class.TestComment, {
|
createClass(test.class.TestComment, {
|
||||||
label: 'TestComment' as IntlString,
|
label: 'TestComment' as IntlString,
|
||||||
|
@ -942,4 +942,31 @@ describe('query', () => {
|
|||||||
const result = await resolveP
|
const result = await resolveP
|
||||||
expect(result.length).toEqual(2)
|
expect(result.length).toEqual(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('check query mixin projection', async () => {
|
||||||
|
const { liveQuery, factory } = await getClient()
|
||||||
|
|
||||||
|
let projects = await liveQuery.queryFind(test.mixin.TestProjectMixin, {}, { projection: { _id: 1 } })
|
||||||
|
expect(projects.length).toEqual(0)
|
||||||
|
const project = await factory.createDoc(test.class.TestProject, core.space.Space, {
|
||||||
|
archived: false,
|
||||||
|
description: '',
|
||||||
|
members: [],
|
||||||
|
private: false,
|
||||||
|
prjName: 'test project',
|
||||||
|
name: 'qwe'
|
||||||
|
})
|
||||||
|
|
||||||
|
projects = await liveQuery.queryFind(test.mixin.TestProjectMixin, {}, { projection: { _id: 1 } })
|
||||||
|
expect(projects.length).toEqual(0)
|
||||||
|
await factory.createMixin(project, test.class.TestProject, core.space.Space, test.mixin.TestProjectMixin, {
|
||||||
|
someField: 'qwe'
|
||||||
|
})
|
||||||
|
// We need to process all events before we could do query again
|
||||||
|
await new Promise<void>((resolve) => {
|
||||||
|
setTimeout(resolve, 100)
|
||||||
|
})
|
||||||
|
projects = await liveQuery.queryFind(test.mixin.TestProjectMixin, {}, { projection: { _id: 1 } })
|
||||||
|
expect(projects.length).toEqual(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -146,7 +146,13 @@ export class TServerStorage implements ServerStorage {
|
|||||||
findOne: async (_class, query, options) => {
|
findOne: async (_class, query, options) => {
|
||||||
return (
|
return (
|
||||||
await metrics.with('query', {}, async (ctx) => {
|
await metrics.with('query', {}, async (ctx) => {
|
||||||
return await this.findAll(ctx, _class, query, { ...options, limit: 1 })
|
const results = await this.findAll(ctx, _class, query, { ...options, limit: 1 })
|
||||||
|
return toFindResult(
|
||||||
|
results.map((v) => {
|
||||||
|
return this.hierarchy.updateLookupMixin(_class, v, options)
|
||||||
|
}),
|
||||||
|
results.total
|
||||||
|
)
|
||||||
})
|
})
|
||||||
)[0]
|
)[0]
|
||||||
},
|
},
|
||||||
@ -232,9 +238,7 @@ export class TServerStorage implements ServerStorage {
|
|||||||
const r = await ctx.with('adapter-tx', { domain: lastDomain }, async (ctx) => await adapter.tx(ctx, ...part))
|
const r = await ctx.with('adapter-tx', { domain: lastDomain }, async (ctx) => await adapter.tx(ctx, ...part))
|
||||||
|
|
||||||
// Update server live queries.
|
// Update server live queries.
|
||||||
for (const t of part) {
|
await this.liveQuery.tx(...part)
|
||||||
await this.liveQuery.tx(t)
|
|
||||||
}
|
|
||||||
if (Array.isArray(r)) {
|
if (Array.isArray(r)) {
|
||||||
result.push(...r)
|
result.push(...r)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user