mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-06 07:46:32 +00:00
Disable aggregation by account for notifications (#5943)
This commit is contained in:
parent
4fb5ca1d17
commit
3394d1ad82
@ -21,6 +21,7 @@ import core, {
|
|||||||
import { getResource, translate } from '@hcengineering/platform'
|
import { getResource, translate } from '@hcengineering/platform'
|
||||||
import { BasePresentationMiddleware, type PresentationMiddleware } from '@hcengineering/presentation'
|
import { BasePresentationMiddleware, type PresentationMiddleware } from '@hcengineering/presentation'
|
||||||
import view, { type IAggregationManager } from '@hcengineering/view'
|
import view, { type IAggregationManager } from '@hcengineering/view'
|
||||||
|
import notification from '@hcengineering/notification'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
@ -105,7 +106,7 @@ export class AggregationMiddleware extends BasePresentationMiddleware implements
|
|||||||
const updatedQuery: DocumentQuery<T> = h.clone(ret.query ?? query)
|
const updatedQuery: DocumentQuery<T> = h.clone(ret.query ?? query)
|
||||||
const finalOptions = h.clone(ret.options ?? options ?? {})
|
const finalOptions = h.clone(ret.options ?? options ?? {})
|
||||||
|
|
||||||
await this.updateQueryOptions<T>(allAttrs, h, statusFields, updatedQuery, finalOptions)
|
await this.updateQueryOptions<T>(allAttrs, h, statusFields, updatedQuery, finalOptions, _class)
|
||||||
|
|
||||||
if (statusFields.length > 0) {
|
if (statusFields.length > 0) {
|
||||||
this.subscribers.set(id, s)
|
this.subscribers.set(id, s)
|
||||||
@ -121,6 +122,31 @@ export class AggregationMiddleware extends BasePresentationMiddleware implements
|
|||||||
return { unsubscribe: ret.unsubscribe }
|
return { unsubscribe: ret.unsubscribe }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: rework notifications to avoid using Account and remove it
|
||||||
|
private shouldAggregate (attrClass: Ref<Class<Doc>>, _class: Ref<Class<Doc>>): 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<Class<Doc>>): Promise<IAggregationManager<any> | undefined> {
|
private async getAggregationManager (_class: Ref<Class<Doc>>): Promise<IAggregationManager<any> | undefined> {
|
||||||
let mgr = this.mgrs.get(_class)
|
let mgr = this.mgrs.get(_class)
|
||||||
|
|
||||||
@ -164,7 +190,7 @@ export class AggregationMiddleware extends BasePresentationMiddleware implements
|
|||||||
|
|
||||||
const fquery = h.clone(query ?? {})
|
const fquery = h.clone(query ?? {})
|
||||||
|
|
||||||
await this.updateQueryOptions<T>(allAttrs, h, docFields, fquery, finalOptions)
|
await this.updateQueryOptions<T>(allAttrs, h, docFields, fquery, finalOptions, _class)
|
||||||
|
|
||||||
return await this.provideFindAll(_class, fquery, finalOptions)
|
return await this.provideFindAll(_class, fquery, finalOptions)
|
||||||
}
|
}
|
||||||
@ -174,13 +200,19 @@ export class AggregationMiddleware extends BasePresentationMiddleware implements
|
|||||||
h: Hierarchy,
|
h: Hierarchy,
|
||||||
docFields: Array<Attribute<Doc>>,
|
docFields: Array<Attribute<Doc>>,
|
||||||
query: DocumentQuery<T>,
|
query: DocumentQuery<T>,
|
||||||
finalOptions: FindOptions<T>
|
finalOptions: FindOptions<T>,
|
||||||
|
_class: Ref<Class<T>>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
for (const attr of allAttrs.values()) {
|
for (const attr of allAttrs.values()) {
|
||||||
try {
|
try {
|
||||||
if (attr.type._class !== core.class.RefTo) {
|
if (attr.type._class !== core.class.RefTo) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.shouldAggregate((attr.type as RefTo<Doc>).to, _class)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
const mgr = await this.getAggregationManager((attr.type as RefTo<Doc>).to)
|
const mgr = await this.getAggregationManager((attr.type as RefTo<Doc>).to)
|
||||||
if (mgr === undefined) {
|
if (mgr === undefined) {
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user