From 995c9c371117fcbf774740a5cfa49f1b3d175f79 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sat, 12 Oct 2024 00:28:40 +0200 Subject: [PATCH] more efficient data representation avoid storing duplicated information for every point in a line --- client-data/js/board.js | 12 +++++++++++- server/boardData.js | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/client-data/js/board.js b/client-data/js/board.js index 2d8c900d..34dc556c 100644 --- a/client-data/js/board.js +++ b/client-data/js/board.js @@ -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++; diff --git a/server/boardData.js b/server/boardData.js index a1f6c0a3..6034a97d 100644 --- a/server/boardData.js +++ b/server/boardData.js @@ -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") {