Skip to content

Commit

Permalink
more efficient data representation
Browse files Browse the repository at this point in the history
avoid storing duplicated information for every point in a line
  • Loading branch information
lovasoa committed Oct 11, 2024
1 parent 83444fe commit 995c9c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion client-data/js/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,20 @@ function handleMessage(message) {
console.error("Received a badly formatted message (no tool). ", message);
}
if (message.tool) messageForTool(message);
if (message._children) return batchCall(handleMessage, message._children);
if (message._children) return batchCall(childMessageHandler(message), message._children);
else return Promise.resolve();
}

// Takes a parent message, and returns a function that will handle a single child message
function childMessageHandler(parent) {
return function handleChild(child) {
if (!child.parent) child.parent = parent.id;
if (!child.type) child.type = "child";
if (!child.tool) child.tool = parent.tool;
return handleMessage(child);
};
}

Tools.unreadMessagesCount = 0;
Tools.newUnreadMessage = function () {
Tools.unreadMessagesCount++;
Expand Down
7 changes: 6 additions & 1 deletion server/boardData.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ class BoardData {
if (id) this.copy(id, message);
break;
case "child":
this.addChild(message.parent, message);
// We don't need to store 'type', 'parent', and 'tool' for each child. They will be rehydrated from the parent on the client side
const parent = message.parent;
delete message.type;
delete message.parent;
delete message.tool;
this.addChild(parent, message);
break;
case "clear":
if (jwtauth.roleInBoard(message.token, message.board) === "moderator") {
Expand Down

0 comments on commit 995c9c3

Please sign in to comment.