mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-09 11:17:43 +02:00
UBERF-7543: Add low level groupBy api and improve security space lookup (#6126)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -23,7 +23,9 @@ import {
|
||||
SearchOptions,
|
||||
SearchQuery,
|
||||
SearchResult,
|
||||
Tx
|
||||
Tx,
|
||||
type Domain,
|
||||
type MeasureContext
|
||||
} from '@hcengineering/core'
|
||||
import { Middleware, SessionContext, TxMiddlewareResult, type ServerStorage } from '@hcengineering/server-core'
|
||||
|
||||
@@ -45,6 +47,17 @@ export abstract class BaseMiddleware {
|
||||
return await this.provideFindAll(ctx, _class, query, options)
|
||||
}
|
||||
|
||||
async providerGroupBy<T>(ctx: MeasureContext, domain: Domain, field: string): Promise<Set<T>> {
|
||||
if (this.next !== undefined) {
|
||||
return await this.next.groupBy(ctx, domain, field)
|
||||
}
|
||||
return await this.storage.groupBy(ctx, domain, field)
|
||||
}
|
||||
|
||||
async groupBy<T>(ctx: MeasureContext, domain: Domain, field: string): Promise<Set<T>> {
|
||||
return await this.providerGroupBy(ctx, domain, field)
|
||||
}
|
||||
|
||||
async searchFulltext (ctx: SessionContext, query: SearchQuery, options: SearchOptions): Promise<SearchResult> {
|
||||
return await this.provideSearchFulltext(ctx, query, options)
|
||||
}
|
||||
|
||||
@@ -450,30 +450,8 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar
|
||||
}
|
||||
|
||||
async loadDomainSpaces (ctx: MeasureContext, domain: Domain): Promise<Set<Ref<Space>>> {
|
||||
const map = new Set<Ref<Space>>()
|
||||
const field = this.getKey(domain)
|
||||
while (true) {
|
||||
const nin = Array.from(map.values())
|
||||
const spaces = await this.storage.findAll(
|
||||
ctx,
|
||||
core.class.Doc,
|
||||
nin.length > 0
|
||||
? {
|
||||
[field]: { $nin: nin }
|
||||
}
|
||||
: {},
|
||||
{
|
||||
projection: { [field]: 1 },
|
||||
limit: 1000,
|
||||
domain
|
||||
}
|
||||
)
|
||||
if (spaces.length === 0) {
|
||||
break
|
||||
}
|
||||
spaces.forEach((p) => map.add((p as any)[field] as Ref<Space>))
|
||||
}
|
||||
return map
|
||||
return await this.storage.groupBy<Ref<Space>>(ctx, domain, field)
|
||||
}
|
||||
|
||||
async getDomainSpaces (domain: Domain): Promise<Set<Ref<Space>>> {
|
||||
|
||||
Reference in New Issue
Block a user