Skip to content

Node.js based forum software built for the modern web

refactor: follow up, clear cache on privilege change for crossposts

Barış Soner Uşaklı321df04696d8
diff --git a/src/cache/tracker.js b/src/cache/tracker.js
index 62277be2cb..32c623c918 100644
--- a/src/cache/tracker.js
+++ b/src/cache/tracker.js
@@ -39,6 +39,10 @@ exports.findCacheByName = function (name) {
return cacheList[name];
};
+exports.resetCache = function (name) {
+ cacheList?.[name]?.reset();
+};
+
exports.resetAll = function () {
for (const cache of Object.values(cacheList)) {
cache.reset();
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index 4963f00145..982bd46862 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -20,7 +20,7 @@ const translator = require('../translator');
const cacheCreate = require('../cache/lru');
const crosspostCache = cacheCreate({
name: 'crosspost',
- size: 500,
+ max: 500,
ttl: 3600000,
});
diff --git a/src/privileges/helpers.js b/src/privileges/helpers.js
index 25d6cd416e..c380a00d47 100644
--- a/src/privileges/helpers.js
+++ b/src/privileges/helpers.js
@@ -10,6 +10,7 @@ const categories = require('../categories');
const plugins = require('../plugins');
const utils = require('../utils');
const activitypub = require('../activitypub');
+const cacheTracker = require('../cache/tracker');
const helpers = module.exports;
@@ -340,6 +341,10 @@ helpers.giveOrRescind = async function (method, privileges, cids, members) {
/* eslint-disable no-await-in-loop */
await method(groupKeys, member);
}
+
+ if (privileges.some(priv => priv === 'groups:topics:crosspost' || priv === 'topics:crosspost')) {
+ cacheTracker.resetCache('crosspost');
+ }
};
helpers.userOrGroupPrivileges = async function (cid, uidOrGroup, privilegeList) {