From 664bf04a018d165835119b1bc693566e159f7fe9 Mon Sep 17 00:00:00 2001 From: Jemma Poffinbarger Date: Mon, 20 Jan 2025 19:53:18 -0600 Subject: [PATCH] fix: updating existing community not updating cache --- src/services/juxt-web/routes/admin/admin.js | 16 ++++------------ src/util.js | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/services/juxt-web/routes/admin/admin.js b/src/services/juxt-web/routes/admin/admin.js index 7c1c061..0f6b186 100644 --- a/src/services/juxt-web/routes/admin/admin.js +++ b/src/services/juxt-web/routes/admin/admin.js @@ -238,7 +238,7 @@ router.post('/communities/new', upload.fields([{ name: 'browserIcon', maxCount: open: true, allows_comments: true, type: req.body.type, - parent: req.body.parent === 'null' ? null : req.body.parent, + parent: req.body.parent === 'null' || req.body.parent.trim() === '' ? null : req.body.parent, owner: req.pid, created_at: moment(new Date()), empathy_count: 0, @@ -255,11 +255,7 @@ router.post('/communities/new', upload.fields([{ name: 'browserIcon', maxCount: await newCommunity.save(); res.redirect(`/admin/communities/${communityID}`); - for (let i = 0; i < document.title_id.length; i++) { - util.communityMap.set(document.title_id[i], document.name); - util.communityMap.set(document.title_id[i] + '-id', document.olive_community_id); - } - util.communityMap.set(document.olive_community_id, document.name); + util.updateCommunityHash(document); }); router.get('/communities/:community_id', async function (req, res) { @@ -329,7 +325,7 @@ router.post('/communities/:id', upload.fields([{ name: 'browserIcon', maxCount: platform_id: req.body.platform, icon: tgaIcon, title_id: req.body.title_ids.replace(/ /g, '').split(','), - parent: req.body.parent === 'null' ? null : req.body.parent, + parent: req.body.parent === 'null' || req.body.parent.trim() === '' ? null : req.body.parent, app_data: req.body.app_data, is_recommended: req.body.is_recommended, name: req.body.name, @@ -339,11 +335,7 @@ router.post('/communities/:id', upload.fields([{ name: 'browserIcon', maxCount: res.redirect(`/admin/communities/${communityID}`); - for (let i = 0; i < document.title_id.length; i++) { - util.communityMap.set(document.title_id[i], document.name); - util.communityMap.set(document.title_id[i] + '-id', document.olive_community_id); - } - util.communityMap.set(document.olive_community_id, document.name); + util.updateCommunityHash(document); }); router.delete('/communities/:id', async (req, res) => { diff --git a/src/util.js b/src/util.js index f66149e..4a49437 100644 --- a/src/util.js +++ b/src/util.js @@ -227,9 +227,21 @@ function setName(pid, name) { if (!pid || !name) { return; } - userMap.delete(pid); - userMap.set(pid, name.replace(/[\u{0080}-\u{FFFF}]/gu, '').replace(/\u202e/g, '')); + this.userMap.delete(pid); + this.userMap.set(pid, name.replace(/[\u{0080}-\u{FFFF}]/gu, '').replace(/\u202e/g, '')); } + +function updateCommunityHash(community) { + if (!community) { + return; + } + for (let i = 0; i < community.title_id.length; i++) { + communityMap.set(community.title_id[i], community.name); + communityMap.set(community.title_id[i] + '-id', community.olive_community_id); + } + communityMap.set(community.olive_community_id, community.name); +} + async function resizeImage(file, width, height) { return new Promise(function (resolve) { const image = Buffer.from(file, 'base64'); @@ -495,6 +507,7 @@ module.exports = { getUserHash, refreshCache, setName, + updateCommunityHash, resizeImage, getTGAFromPNG, createBMPTgaBuffer,