Skip to content

Commit

Permalink
fix native response processing via websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Dec 18, 2024
1 parent daf13de commit b216969
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/cubejs-server/src/websocket-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ export class WebSocketServer {
throw new Error(`Socket for ${connectionId} is not found found`);
}

connectionIdToSocket[connectionId].send(JSON.stringify(message));
let messageStr: string;

if (message.message instanceof ArrayBuffer) {
// In case we already have a JSON-serialized query result, we don't want to parse/stringify
// it again - it's too expensive, instead we serialize the rest of the message and then
// inject query result json into message.
const resMsg = new TextDecoder().decode(message.message);
message.message = "~XXXXX~";
messageStr = JSON.stringify(message);
messageStr = messageStr.replace(`"~XXXXX~"`, resMsg);
} else {
messageStr = JSON.stringify(message);
}

connectionIdToSocket[connectionId].send(messageStr);
});

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

0 comments on commit b216969

Please sign in to comment.