mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-21 09:31:17 -08:00
perf: reuse the SDK singleton PushProcessor instead of allocating per call
new PushProcessor(room.client) was allocated per room on every sync cycle (in the getUnreadInfo fallback path) and per component mount in RoomTimeline/ThreadDrawer/notifications. The SDK already exposes a cached singleton at mx.pushProcessor (client.ts:1293). Element Web uses the same pattern. Replace all five allocations and drop the now-unused imports.
This commit is contained in:
5 files changed
+6
-10
No files matched your search
@@ -12,7 +12,7 @@ import {
|
||||
import type { Editor } from 'slate';
|
||||
import { useAtomValue, useSetAtom, useStore } from 'jotai';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
import { PushProcessor, Direction, EventType } from '$types/matrix-sdk';
|
||||
import { Direction, EventType } from '$types/matrix-sdk';
|
||||
import classNames from 'classnames';
|
||||
import type { VListHandle } from 'virtua';
|
||||
import { VList } from 'virtua';
|
||||
@@ -428,7 +428,7 @@ export function RoomTimeline({
|
||||
const optionalSpace = useSpaceOptionally();
|
||||
const roomParents = useAtomValue(roomToParentsAtom);
|
||||
const imagePackRooms = useImagePackRooms(room.roomId, roomParents);
|
||||
const pushProcessor = useMemo(() => new PushProcessor(mx), [mx]);
|
||||
const pushProcessor = mx.pushProcessor;
|
||||
const parseMemberEvent = useMemberEventParser();
|
||||
|
||||
const replyDraftAtom = useMemo(() => roomIdToReplyDraftAtomFamily(room.roomId), [room.roomId]);
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
Direction,
|
||||
MatrixEvent,
|
||||
MatrixEventEvent,
|
||||
PushProcessor,
|
||||
ReceiptType,
|
||||
RelationType,
|
||||
RoomEvent,
|
||||
@@ -137,7 +136,7 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
|
||||
(userId: string) => jotaiStore.get(profilesCacheAtom)[userId],
|
||||
[jotaiStore]
|
||||
);
|
||||
const pushProcessor = useMemo(() => new PushProcessor(mx), [mx]);
|
||||
const pushProcessor = mx.pushProcessor;
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const mentionClickHandler = useMentionClickHandler(room.roomId);
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
MatrixEventEvent,
|
||||
RoomEvent,
|
||||
SyncState,
|
||||
PushProcessor,
|
||||
EventType,
|
||||
} from '$types/matrix-sdk';
|
||||
|
||||
@@ -327,7 +326,7 @@ export function BackgroundNotifications() {
|
||||
});
|
||||
}
|
||||
|
||||
const pushProcessor = new PushProcessor(mx);
|
||||
const pushProcessor = mx.pushProcessor;
|
||||
|
||||
const handleAccountData = (event: MatrixEvent) => {
|
||||
if (event.getType() === (EventType.Direct as string)) {
|
||||
|
||||
@@ -11,7 +11,6 @@ import { getPresenceSyncManager } from '$client/initMatrix';
|
||||
import {
|
||||
MatrixEvent,
|
||||
MatrixEventEvent,
|
||||
PushProcessor,
|
||||
RoomEvent,
|
||||
SetPresence,
|
||||
SyncState,
|
||||
@@ -339,7 +338,7 @@ function MessageNotifications() {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const pushProcessor = new PushProcessor(mx);
|
||||
const pushProcessor = mx.pushProcessor;
|
||||
// Track encrypted events that should skip focus check when decrypted (because we
|
||||
// already checked focus when the encrypted event arrived, and want to use that
|
||||
// original state rather than re-checking after decryption completes).
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
EventTimeline,
|
||||
EventType,
|
||||
NotificationCountType,
|
||||
PushProcessor,
|
||||
PushRuleActionName,
|
||||
RelationType,
|
||||
MsgType,
|
||||
@@ -427,7 +426,7 @@ export const getUnreadInfo = (room: Room, options?: UnreadInfoOptions): UnreadIn
|
||||
const liveEvents = room.getLiveTimeline().getEvents();
|
||||
let fallbackTotal = 0;
|
||||
let fallbackHighlight = 0;
|
||||
const pushProcessor = new PushProcessor(room.client);
|
||||
const pushProcessor = room.client.pushProcessor;
|
||||
for (let i = liveEvents.length - 1; i >= 0; i -= 1) {
|
||||
const event = liveEvents[i];
|
||||
if (!event) break;
|
||||
|
||||
Reference in new issue
Block a user