perf(core): Skip serialization for push messages with no recipients (#25308)

This commit is contained in:
Iván Ovejero
2026-02-04 13:52:32 +01:00
committed by GitHub
parent a5541fe65d
commit f4de4300a2
2 changed files with 9 additions and 0 deletions
@@ -107,6 +107,13 @@ describe('WebSocketPush', () => {
expect(mockWebSocket2.send).toHaveBeenCalledWith(expectedMsg, { binary: false });
});
it('skips sending when user has no connections', () => {
webSocketPush.add(pushRef1, userId, mockWebSocket1);
webSocketPush.sendToUsers(pushMessage, ['nonexistent-user']);
expect(mockWebSocket1.send).not.toHaveBeenCalled();
});
it('emits message event when connection receives data', async () => {
jest.useRealTimers();
const mockOnMessageReceived = jest.fn();
+2
View File
@@ -74,6 +74,8 @@ export abstract class AbstractPush<Connection> extends TypedEmitter<AbstractPush
}
private sendTo({ type, data }: PushMessage, pushRefs: string[], asBinary: boolean = false) {
if (pushRefs.length === 0) return;
this.logger.debug(`Pushed to frontend: ${type}`, {
dataType: type,
pushRefs: pushRefs.join(', '),