From 2c9ee04c6db2024a2dae46f67b0b4ce4f91c3f17 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Thu, 15 Dec 2022 21:30:15 +0100 Subject: [PATCH] Optimise chat storage by not storing both equipped and costume (#14409) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * don’t store both equipped and costume * fix lint --- .../api/v3/integration/chat/POST-chat.test.js | 29 +++++++++++++++++++ website/server/models/message.js | 7 +++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/test/api/v3/integration/chat/POST-chat.test.js b/test/api/v3/integration/chat/POST-chat.test.js index 73ee343c79..d88ddd1d2b 100644 --- a/test/api/v3/integration/chat/POST-chat.test.js +++ b/test/api/v3/integration/chat/POST-chat.test.js @@ -541,6 +541,35 @@ describe('POST /chat', () => { .to.eql(userWithStyle.preferences.background); }); + it('creates equipped to user styles', async () => { + const userWithStyle = await generateUser({ + 'preferences.costume': false, + 'auth.timestamps.created': new Date('2022-01-01'), + }); + await userWithStyle.sync(); + + const message = await userWithStyle.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage }); + + expect(message.message.id).to.exist; + expect(message.message.userStyles.items.gear.equipped) + .to.eql(userWithStyle.items.gear.equipped); + expect(message.message.userStyles.items.gear.costume).to.not.exist; + }); + + it('creates costume to user styles', async () => { + const userWithStyle = await generateUser({ + 'preferences.costume': true, + 'auth.timestamps.created': new Date('2022-01-01'), + }); + await userWithStyle.sync(); + + const message = await userWithStyle.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage }); + + expect(message.message.id).to.exist; + expect(message.message.userStyles.items.gear.costume).to.eql(userWithStyle.items.gear.costume); + expect(message.message.userStyles.items.gear.equipped).to.not.exist; + }); + it('adds backer info to chat', async () => { const backerInfo = { npc: 'Town Crier', diff --git a/website/server/models/message.js b/website/server/models/message.js index 5f4ad89515..f8ae3a1df4 100644 --- a/website/server/models/message.js +++ b/website/server/models/message.js @@ -67,8 +67,11 @@ export function setUserStyles (newMessage, user) { if (userCopy.items) { userStyles.items.gear = {}; - userStyles.items.gear.costume = { ...userCopy.items.gear.costume }; - userStyles.items.gear.equipped = { ...userCopy.items.gear.equipped }; + if (userCopy.preferences && userCopy.preferences.costume) { + userStyles.items.gear.costume = { ...userCopy.items.gear.costume }; + } else { + userStyles.items.gear.equipped = { ...userCopy.items.gear.equipped }; + } userStyles.items.currentMount = userCopy.items.currentMount; userStyles.items.currentPet = userCopy.items.currentPet;