diff --git a/plugins/view-resources/src/middleware.ts b/plugins/view-resources/src/middleware.ts index 68afd5843e..09d1f10f82 100644 --- a/plugins/view-resources/src/middleware.ts +++ b/plugins/view-resources/src/middleware.ts @@ -21,6 +21,7 @@ import core, { import { getResource, translate } from '@hcengineering/platform' import { BasePresentationMiddleware, type PresentationMiddleware } from '@hcengineering/presentation' import view, { type IAggregationManager } from '@hcengineering/view' +import notification from '@hcengineering/notification' /** * @public @@ -105,7 +106,7 @@ export class AggregationMiddleware extends BasePresentationMiddleware implements const updatedQuery: DocumentQuery = h.clone(ret.query ?? query) const finalOptions = h.clone(ret.options ?? options ?? {}) - await this.updateQueryOptions(allAttrs, h, statusFields, updatedQuery, finalOptions) + await this.updateQueryOptions(allAttrs, h, statusFields, updatedQuery, finalOptions, _class) if (statusFields.length > 0) { this.subscribers.set(id, s) @@ -121,6 +122,31 @@ export class AggregationMiddleware extends BasePresentationMiddleware implements return { unsubscribe: ret.unsubscribe } } + // TODO: rework notifications to avoid using Account and remove it + private shouldAggregate (attrClass: Ref>, _class: Ref>): boolean { + if (attrClass !== core.class.Account) { + return true + } + + const h = this.client.getHierarchy() + const skipAccountAggregation = [ + notification.class.BrowserNotification, + notification.class.InboxNotification, + notification.class.DocNotifyContext + ] + + for (const skipClass of skipAccountAggregation) { + if (_class === skipClass) { + return false + } + + if (h.isDerived(_class, skipClass)) { + return false + } + } + return true + } + private async getAggregationManager (_class: Ref>): Promise | undefined> { let mgr = this.mgrs.get(_class) @@ -164,7 +190,7 @@ export class AggregationMiddleware extends BasePresentationMiddleware implements const fquery = h.clone(query ?? {}) - await this.updateQueryOptions(allAttrs, h, docFields, fquery, finalOptions) + await this.updateQueryOptions(allAttrs, h, docFields, fquery, finalOptions, _class) return await this.provideFindAll(_class, fquery, finalOptions) } @@ -174,13 +200,19 @@ export class AggregationMiddleware extends BasePresentationMiddleware implements h: Hierarchy, docFields: Array>, query: DocumentQuery, - finalOptions: FindOptions + finalOptions: FindOptions, + _class: Ref> ): Promise { for (const attr of allAttrs.values()) { try { if (attr.type._class !== core.class.RefTo) { continue } + + if (!this.shouldAggregate((attr.type as RefTo).to, _class)) { + continue + } + const mgr = await this.getAggregationManager((attr.type as RefTo).to) if (mgr === undefined) { continue