Skip to content

Commit 2f855fe

Browse files
committed
refactor(server): send compact like update to waiting clients
- Create dataToSendToClient containing only message id and likes - Notify long-polling clients with the minimized payload instead of the full message object - Respond to the liker with the same compact payload - Reduce payload size and clarify notification format
1 parent a86e070 commit 2f855fe

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

chat-app/backend/server.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,20 @@ app.post("/messages/:id/like", (req, res) => {
105105
// Get a snapshot list of all the clients' callback in the waiting room (Array)
106106
const waitingCallbacks = Object.values(callBacksForNewMessages);
107107

108+
const dataToSendToClient = {
109+
id: messageWithIdAsNumber.id,
110+
likes: messageWithIdAsNumber.likes
111+
}
112+
108113
if (waitingCallbacks.length > 0) {
109114
waitingCallbacks.forEach((eachClient) => {
110-
eachClient([messageWithIdAsNumber]);
115+
eachClient([dataToSendToClient]);
111116
});
112117

113118
// clear the waiting room
114119
callBacksForNewMessages = {};
115120
}
116-
res.status(200).send(messageWithIdAsNumber);
121+
res.status(200).send(dataToSendToClient);
117122
});
118123

119124
// Start the server

0 commit comments

Comments
 (0)