From 85385295a6179af1d3b6acc5112c7594d39b9a90 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 4 May 2021 13:31:04 +0200 Subject: [PATCH] don't serialize null values in room summary they only take space in the storage otherwise as we add more fields --- src/matrix/room/RoomSummary.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/matrix/room/RoomSummary.js b/src/matrix/room/RoomSummary.js index 88b2c45b..fe3e2a92 100644 --- a/src/matrix/room/RoomSummary.js +++ b/src/matrix/room/RoomSummary.js @@ -205,7 +205,12 @@ export class SummaryData { serialize() { const {cloned, ...serializedProps} = this; - return serializedProps; + return Object.entries(this).reduce((obj, [key, value]) => { + if (key !== "cloned" && value !== null) { + obj[key] = value; + } + return obj; + }, {}); } applyTimelineEntries(timelineEntries, isInitialSync, canMarkUnread, ownUserId) { @@ -297,6 +302,16 @@ export class RoomSummary { export function tests() { return { + "serialize doesn't include null fields or cloned": assert => { + const roomId = "!123:hs.tld"; + const data = new SummaryData(null, roomId); + const clone = data.cloneIfNeeded(); + const serialized = clone.serialize(); + assert.strictEqual(serialized.cloned, undefined); + assert.equal(serialized.roomId, roomId); + const nullCount = Object.values(serialized).reduce((count, value) => count + value === null ? 1 : 0, 0); + assert.strictEqual(nullCount, 0); + }, "membership trigger change": function(assert) { const summary = new RoomSummary("id"); let written = false;