Skip to content

Commit f5e6aec

Browse files
committed
fix native response processing via websocket
1 parent 34d0085 commit f5e6aec

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/cubejs-server/src/websocket-server.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,21 @@ export class WebSocketServer {
3636
throw new Error(`Socket for ${connectionId} is not found found`);
3737
}
3838

39-
connectionIdToSocket[connectionId].send(JSON.stringify(message));
39+
let messageStr: string;
40+
41+
if (message.message instanceof ArrayBuffer) {
42+
// In case we already have a JSON-serialized query result, we don't want to parse/stringify
43+
// it again - it's too expensive, instead we serialize the rest of the message and then
44+
// inject query result json into message.
45+
const resMsg = new TextDecoder().decode(message.message);
46+
message.message = "~XXXXX~";
47+
messageStr = JSON.stringify(message);
48+
messageStr = messageStr.replace(`"~XXXXX~"`, resMsg);
49+
} else {
50+
messageStr = JSON.stringify(message);
51+
}
52+
53+
connectionIdToSocket[connectionId].send(messageStr);
4054
});
4155

4256
this.wsServer.on('connection', (ws) => {

0 commit comments

Comments
 (0)