Throttle notification state calculation (#31922)
Because every room in a space will emit a notification state change when push rules change so we would otherwise recalculate the space notification state for every room in the space, On^2 style.
This commit is contained in:
@@ -6,6 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { throttle } from "lodash";
|
||||||
import { type Room } from "matrix-js-sdk/src/matrix";
|
import { type Room } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { NotificationLevel } from "./NotificationLevel";
|
import { NotificationLevel } from "./NotificationLevel";
|
||||||
@@ -63,7 +64,8 @@ export class SpaceNotificationState extends NotificationState {
|
|||||||
this.calculateTotalState();
|
this.calculateTotalState();
|
||||||
};
|
};
|
||||||
|
|
||||||
private calculateTotalState(): void {
|
private calculateTotalState = throttle(
|
||||||
|
(): void => {
|
||||||
const snapshot = this.snapshot();
|
const snapshot = this.snapshot();
|
||||||
|
|
||||||
this._count = 0;
|
this._count = 0;
|
||||||
@@ -81,5 +83,8 @@ export class SpaceNotificationState extends NotificationState {
|
|||||||
|
|
||||||
// finally, publish an update if needed
|
// finally, publish an update if needed
|
||||||
this.emitIfUpdated(snapshot);
|
this.emitIfUpdated(snapshot);
|
||||||
}
|
},
|
||||||
|
100,
|
||||||
|
{ leading: false, trailing: true },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user