add max to caches to limit memory usage

This commit is contained in:
Barış Soner Uşaklı
2024-06-04 12:31:13 -04:00
parent 6f37825b1a
commit 300cf79c95
3 changed files with 18 additions and 7 deletions

View File

@@ -16,7 +16,10 @@ const user = require('../user');
const activitypub = require('.');
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;
@@ -59,8 +62,9 @@ Helpers.query = async (id) => {
return false;
}
if (webfingerCache.has(id)) {
return webfingerCache.get(id);
const cached = webfingerCache.get(id);
if (cached !== undefined) {
return cached;
}
const query = new URLSearchParams({ resource: uri });