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-5538: Fix server queryFind with mixins #4653

Merged
merged 1 commit into from
Feb 15, 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
11 changes: 11 additions & 0 deletions packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class LiveQuery extends TxProcessor implements Client {
options.projection = {
...options.projection,
_class: 1,
space: 1,
modifiedOn: 1
}
}
Expand Down Expand Up @@ -209,6 +210,7 @@ export class LiveQuery extends TxProcessor implements Client {
options.projection = {
...options.projection,
_class: 1,
space: 1,
modifiedOn: 1
}
}
Expand Down Expand Up @@ -341,6 +343,7 @@ export class LiveQuery extends TxProcessor implements Client {
options.projection = {
...options.projection,
_class: 1,
space: 1,
modifiedOn: 1
}
}
Expand All @@ -362,6 +365,14 @@ export class LiveQuery extends TxProcessor implements Client {
query: DocumentQuery<T>,
options?: FindOptions<T>
): Promise<FindResult<T>> {
if (options?.projection !== undefined) {
options.projection = {
...options.projection,
_class: 1,
space: 1,
modifiedOn: 1
}
}
const current = this.findQuery(_class, query, options)
if (current === undefined) {
const q = this.createQuery(
Expand Down
21 changes: 14 additions & 7 deletions server/core/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ import core, {
WorkspaceEvent,
WorkspaceId,
WorkspaceIdWithUrl,
generateId
generateId,
toFindResult
} from '@hcengineering/core'
import { MinioService } from '@hcengineering/minio'
import { Metadata, getResource } from '@hcengineering/platform'
Expand Down Expand Up @@ -143,15 +144,21 @@ class TServerStorage implements ServerStorage {
},
close: async () => {},
findAll: async (_class, query, options) => {
return await metrics.with('query', {}, async (ctx) => await this.findAll(ctx, _class, query, options))
return await metrics.with('query', {}, async (ctx) => {
const results = await this.findAll(ctx, _class, query, options)
return toFindResult(
results.map((v) => {
return this.hierarchy.updateLookupMixin(_class, v, options)
}),
results.total
)
})
},
findOne: async (_class, query, options) => {
return (
await metrics.with(
'query',
{},
async (ctx) => await this.findAll(ctx, _class, query, { ...options, limit: 1 })
)
await metrics.with('query', {}, async (ctx) => {
return await this.findAll(ctx, _class, query, { ...options, limit: 1 })
})
)[0]
},
tx: async (tx) => {
Expand Down
15 changes: 5 additions & 10 deletions server/mongo/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import core, {
DOMAIN_MODEL,
DOMAIN_TX,
MeasureMetricsContext,
SortingOrder,
TxProcessor,
cutObjectArray,
Expand Down Expand Up @@ -112,13 +111,9 @@ abstract class MongoAdapterBase implements DbAdapter {

async init (): Promise<void> {}

async toArray<T>(ctx: MeasureContext, cursor: AbstractCursor<T>): Promise<T[]> {
const st = Date.now()
async toArray<T>(cursor: AbstractCursor<T>): Promise<T[]> {
const data = await cursor.toArray()
await cursor.close()
if (Date.now() - st > 1000) {
console.error('toArray', Date.now() - st, data.length)
}
return data
}

Expand Down Expand Up @@ -480,7 +475,7 @@ abstract class MongoAdapterBase implements DbAdapter {
const result: WithLookup<T>[] = []
let total = options?.total === true ? 0 : -1
try {
const rres = await ctx.with('toArray', {}, async (ctx) => await this.toArray(ctx, cursor), {
const rres = await ctx.with('toArray', {}, async (ctx) => await this.toArray(cursor), {
domain,
pipeline
})
Expand Down Expand Up @@ -626,7 +621,7 @@ abstract class MongoAdapterBase implements DbAdapter {

// Error in case of timeout
try {
const res: T[] = await ctx.with('toArray', {}, async (ctx) => await this.toArray(ctx, cursor), {
const res: T[] = await ctx.with('toArray', {}, async (ctx) => await this.toArray(cursor), {
mongoQuery,
options,
domain
Expand Down Expand Up @@ -795,7 +790,7 @@ abstract class MongoAdapterBase implements DbAdapter {
return []
}
const cursor = this.db.collection<Doc>(domain).find<Doc>({ _id: { $in: docs } }, { limit: docs.length })
const result = await this.toArray(new MeasureMetricsContext('', {}), cursor)
const result = await this.toArray(cursor)
return this.stripHash(this.stripHash(result))
}

Expand Down Expand Up @@ -1262,7 +1257,7 @@ class MongoTxAdapter extends MongoAdapterBase implements TxAdapter {
.collection(DOMAIN_TX)
.find<Tx>({ objectSpace: core.space.Model })
.sort({ _id: 1, modifiedOn: 1 })
const model = await this.toArray(new MeasureMetricsContext('', {}), cursor)
const model = await this.toArray(cursor)
// We need to put all core.account.System transactions first
const systemTx: Tx[] = []
const userTx: Tx[] = []
Expand Down
Loading