mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-15 04:49:00 +00:00
UBERF-5538: Fix server queryFind with mixins (#4653)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
83f878a9bd
commit
96b81eabef
@ -180,6 +180,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
options.projection = {
|
options.projection = {
|
||||||
...options.projection,
|
...options.projection,
|
||||||
_class: 1,
|
_class: 1,
|
||||||
|
space: 1,
|
||||||
modifiedOn: 1
|
modifiedOn: 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,6 +210,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
options.projection = {
|
options.projection = {
|
||||||
...options.projection,
|
...options.projection,
|
||||||
_class: 1,
|
_class: 1,
|
||||||
|
space: 1,
|
||||||
modifiedOn: 1
|
modifiedOn: 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -341,6 +343,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
options.projection = {
|
options.projection = {
|
||||||
...options.projection,
|
...options.projection,
|
||||||
_class: 1,
|
_class: 1,
|
||||||
|
space: 1,
|
||||||
modifiedOn: 1
|
modifiedOn: 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,6 +365,14 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
query: DocumentQuery<T>,
|
query: DocumentQuery<T>,
|
||||||
options?: FindOptions<T>
|
options?: FindOptions<T>
|
||||||
): Promise<FindResult<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)
|
const current = this.findQuery(_class, query, options)
|
||||||
if (current === undefined) {
|
if (current === undefined) {
|
||||||
const q = this.createQuery(
|
const q = this.createQuery(
|
||||||
|
@ -55,7 +55,8 @@ import core, {
|
|||||||
WorkspaceEvent,
|
WorkspaceEvent,
|
||||||
WorkspaceId,
|
WorkspaceId,
|
||||||
WorkspaceIdWithUrl,
|
WorkspaceIdWithUrl,
|
||||||
generateId
|
generateId,
|
||||||
|
toFindResult
|
||||||
} from '@hcengineering/core'
|
} from '@hcengineering/core'
|
||||||
import { MinioService } from '@hcengineering/minio'
|
import { MinioService } from '@hcengineering/minio'
|
||||||
import { Metadata, getResource } from '@hcengineering/platform'
|
import { Metadata, getResource } from '@hcengineering/platform'
|
||||||
@ -143,15 +144,21 @@ class TServerStorage implements ServerStorage {
|
|||||||
},
|
},
|
||||||
close: async () => {},
|
close: async () => {},
|
||||||
findAll: async (_class, query, options) => {
|
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) => {
|
findOne: async (_class, query, options) => {
|
||||||
return (
|
return (
|
||||||
await metrics.with(
|
await metrics.with('query', {}, async (ctx) => {
|
||||||
'query',
|
return await this.findAll(ctx, _class, query, { ...options, limit: 1 })
|
||||||
{},
|
})
|
||||||
async (ctx) => await this.findAll(ctx, _class, query, { ...options, limit: 1 })
|
|
||||||
)
|
|
||||||
)[0]
|
)[0]
|
||||||
},
|
},
|
||||||
tx: async (tx) => {
|
tx: async (tx) => {
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
import core, {
|
import core, {
|
||||||
DOMAIN_MODEL,
|
DOMAIN_MODEL,
|
||||||
DOMAIN_TX,
|
DOMAIN_TX,
|
||||||
MeasureMetricsContext,
|
|
||||||
SortingOrder,
|
SortingOrder,
|
||||||
TxProcessor,
|
TxProcessor,
|
||||||
cutObjectArray,
|
cutObjectArray,
|
||||||
@ -112,13 +111,9 @@ abstract class MongoAdapterBase implements DbAdapter {
|
|||||||
|
|
||||||
async init (): Promise<void> {}
|
async init (): Promise<void> {}
|
||||||
|
|
||||||
async toArray<T>(ctx: MeasureContext, cursor: AbstractCursor<T>): Promise<T[]> {
|
async toArray<T>(cursor: AbstractCursor<T>): Promise<T[]> {
|
||||||
const st = Date.now()
|
|
||||||
const data = await cursor.toArray()
|
const data = await cursor.toArray()
|
||||||
await cursor.close()
|
await cursor.close()
|
||||||
if (Date.now() - st > 1000) {
|
|
||||||
console.error('toArray', Date.now() - st, data.length)
|
|
||||||
}
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,7 +475,7 @@ abstract class MongoAdapterBase implements DbAdapter {
|
|||||||
const result: WithLookup<T>[] = []
|
const result: WithLookup<T>[] = []
|
||||||
let total = options?.total === true ? 0 : -1
|
let total = options?.total === true ? 0 : -1
|
||||||
try {
|
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,
|
domain,
|
||||||
pipeline
|
pipeline
|
||||||
})
|
})
|
||||||
@ -626,7 +621,7 @@ abstract class MongoAdapterBase implements DbAdapter {
|
|||||||
|
|
||||||
// Error in case of timeout
|
// Error in case of timeout
|
||||||
try {
|
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,
|
mongoQuery,
|
||||||
options,
|
options,
|
||||||
domain
|
domain
|
||||||
@ -795,7 +790,7 @@ abstract class MongoAdapterBase implements DbAdapter {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const cursor = this.db.collection<Doc>(domain).find<Doc>({ _id: { $in: docs } }, { limit: docs.length })
|
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))
|
return this.stripHash(this.stripHash(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1262,7 +1257,7 @@ class MongoTxAdapter extends MongoAdapterBase implements TxAdapter {
|
|||||||
.collection(DOMAIN_TX)
|
.collection(DOMAIN_TX)
|
||||||
.find<Tx>({ objectSpace: core.space.Model })
|
.find<Tx>({ objectSpace: core.space.Model })
|
||||||
.sort({ _id: 1, modifiedOn: 1 })
|
.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
|
// We need to put all core.account.System transactions first
|
||||||
const systemTx: Tx[] = []
|
const systemTx: Tx[] = []
|
||||||
const userTx: Tx[] = []
|
const userTx: Tx[] = []
|
||||||
|
Loading…
Reference in New Issue
Block a user