Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-7247: Fix queryFind for mixins on server #5803

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 64 additions & 9 deletions packages/query/src/__tests__/minmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@
// 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 type { IntlString, Plugin } from '@hcengineering/platform'
import { plugin } from '@hcengineering/platform'
Expand Down Expand Up @@ -54,16 +67,26 @@ export interface AttachedComment extends AttachedDoc {
message: string
}

interface TestProject extends Space {
prjName: string
}

interface TestProjectMixin extends TestProject {
someField?: string
}

/**
* @public
*/
export const test = plugin('test' as Plugin, {
mixin: {
TestMixin: '' as Ref<Mixin<TestMixin>>
TestMixin: '' as Ref<Mixin<TestMixin>>,
TestProjectMixin: '' as Ref<Mixin<TestProjectMixin>>
},
class: {
TestComment: '' as Ref<Class<AttachedComment>>,
ParticipantsHolder: '' as Ref<Class<ParticipantsHolder>>
ParticipantsHolder: '' as Ref<Class<ParticipantsHolder>>,
TestProject: '' as Ref<Class<TestProject>>
}
})

Expand All @@ -89,20 +112,28 @@ export function genMinModel (): TxCUD<Doc>[] {
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,
createClass(core.class.Class, {
label: 'Class' as IntlString,
extends: core.class.Doc,
kind: ClassifierKind.MIXIN
kind: ClassifierKind.CLASS,
domain: DOMAIN_MODEL
})
)
txes.push(
createClass(core.class.Class, {
label: 'Class' as IntlString,
extends: core.class.Doc,
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(
createClass(core.class.Space, {
label: 'Space' as IntlString,
Expand Down Expand Up @@ -164,6 +195,13 @@ export function genMinModel (): TxCUD<Doc>[] {
kind: ClassifierKind.CLASS
})
)
txes.push(
createClass(core.class.TxMixin, {
label: 'TxMixin' as IntlString,
extends: core.class.TxCUD,
kind: ClassifierKind.CLASS
})
)

txes.push(
createClass(test.mixin.TestMixin, {
Expand All @@ -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(
createClass(test.class.TestComment, {
label: 'TestComment' as IntlString,
Expand Down
27 changes: 27 additions & 0 deletions packages/query/src/__tests__/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,4 +942,31 @@ describe('query', () => {
const result = await resolveP
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)
})
})
12 changes: 8 additions & 4 deletions server/core/src/server/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ export class TServerStorage implements ServerStorage {
findOne: async (_class, query, options) => {
return (
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]
},
Expand Down Expand Up @@ -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))

// Update server live queries.
for (const t of part) {
await this.liveQuery.tx(t)
}
await this.liveQuery.tx(...part)
if (Array.isArray(r)) {
result.push(...r)
} else {
Expand Down