mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
add max to caches to limit memory usage
This commit is contained in:
@@ -8,7 +8,10 @@ const user = require('../user');
|
|||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
const TTLCache = require('../cache/ttl');
|
const TTLCache = require('../cache/ttl');
|
||||||
|
|
||||||
const failedWebfingerCache = TTLCache({ ttl: 1000 * 60 * 10 }); // 10 minutes
|
const failedWebfingerCache = TTLCache({
|
||||||
|
max: 5000,
|
||||||
|
ttl: 1000 * 60 * 10, // 10 minutes
|
||||||
|
});
|
||||||
|
|
||||||
const activitypub = module.parent.exports;
|
const activitypub = module.parent.exports;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ const user = require('../user');
|
|||||||
const activitypub = require('.');
|
const activitypub = require('.');
|
||||||
|
|
||||||
const webfingerRegex = /^(@|acct:)?[\w\-]+@.+$/;
|
const webfingerRegex = /^(@|acct:)?[\w\-]+@.+$/;
|
||||||
const webfingerCache = ttl({ ttl: 1000 * 60 * 60 * 24 }); // 24 hours
|
const webfingerCache = ttl({
|
||||||
|
max: 5000,
|
||||||
|
ttl: 1000 * 60 * 60 * 24, // 24 hours
|
||||||
|
});
|
||||||
|
|
||||||
const Helpers = module.exports;
|
const Helpers = module.exports;
|
||||||
|
|
||||||
@@ -59,8 +62,9 @@ Helpers.query = async (id) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (webfingerCache.has(id)) {
|
const cached = webfingerCache.get(id);
|
||||||
return webfingerCache.get(id);
|
if (cached !== undefined) {
|
||||||
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = new URLSearchParams({ resource: uri });
|
const query = new URLSearchParams({ resource: uri });
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ const batch = require('../batch');
|
|||||||
const pubsub = require('../pubsub');
|
const pubsub = require('../pubsub');
|
||||||
const analytics = require('../analytics');
|
const analytics = require('../analytics');
|
||||||
|
|
||||||
const requestCache = ttl({ ttl: 1000 * 60 * 5 }); // 5 minutes
|
const requestCache = ttl({
|
||||||
|
max: 5000,
|
||||||
|
ttl: 1000 * 60 * 5, // 5 minutes
|
||||||
|
});
|
||||||
const ActivityPub = module.exports;
|
const ActivityPub = module.exports;
|
||||||
|
|
||||||
ActivityPub._constants = Object.freeze({
|
ActivityPub._constants = Object.freeze({
|
||||||
@@ -223,8 +226,9 @@ ActivityPub.verify = async (req) => {
|
|||||||
|
|
||||||
ActivityPub.get = async (type, id, uri) => {
|
ActivityPub.get = async (type, id, uri) => {
|
||||||
const cacheKey = [id, uri].join(';');
|
const cacheKey = [id, uri].join(';');
|
||||||
if (requestCache.has(cacheKey)) {
|
const cached = requestCache.get(cacheKey);
|
||||||
return requestCache.get(cacheKey);
|
if (cached !== undefined) {
|
||||||
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
const keyData = await ActivityPub.getPrivateKey(type, id);
|
const keyData = await ActivityPub.getPrivateKey(type, id);
|
||||||
|
|||||||
Reference in New Issue
Block a user