mirror of
https://github.com/n8n-io/n8n.git
synced 2026-08-30 18:01:23 +08:00
perf(core): Skip serialization for push messages with no recipients (#25308)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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(', '),
|
||||
|
||||
Reference in New Issue
Block a user