Skip to content

Commit

Permalink
fix: updating existing community not updating cache
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelKat committed Jan 21, 2025
1 parent 08dae2f commit 664bf04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
16 changes: 4 additions & 12 deletions src/services/juxt-web/routes/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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) => {
Expand Down
17 changes: 15 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -495,6 +507,7 @@ module.exports = {
getUserHash,
refreshCache,
setName,
updateCommunityHash,
resizeImage,
getTGAFromPNG,
createBMPTgaBuffer,
Expand Down

0 comments on commit 664bf04

Please sign in to comment.