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:
Andrey Sobolev
2024-07-28 14:55:42 +07:00
committed by Andrey Sobolev
parent 3bec396384
commit aa1bbd6247
12 changed files with 130 additions and 34 deletions
+14 -1
View File
@@ -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)
}
+1 -23
View File
@@ -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>>> {