Node.js based forum software built for the modern web
feat: add webfinger ttl cache
Julian Lam4f5f025d5776
diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.jsindex 7c77462839..d001cfb2ed 100644--- a/src/activitypub/helpers.js+++ b/src/activitypub/helpers.js@@ -2,6 +2,10 @@const request = require('request-promise-native');+const ttl = require('../cache/ttl');++const webfingerCache = ttl({ ttl: 1000 * 60 * 60 * 24 }); // 24 hours+const Helpers = module.exports;Helpers.query = async (id) => {@@ -10,6 +14,10 @@ Helpers.query = async (id) => {return false;}+ if (webfingerCache.has(id)) {+ return webfingerCache.get(id);+ }+// Make a webfinger query to retrieve routing informationconst response = await request(`https://${hostname}/.well-known/webfinger?resource=acct:${id}`, {simple: false,@@ -28,5 +36,6 @@ Helpers.query = async (id) => {({ href: actorUri } = actorUri);}+ webfingerCache.set(id, { username, hostname, actorUri });return { username, hostname, actorUri };};