summaryrefslogtreecommitdiff
path: root/src/services/register-or-fetch-instance-doc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/register-or-fetch-instance-doc.ts')
-rw-r--r--src/services/register-or-fetch-instance-doc.ts8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/services/register-or-fetch-instance-doc.ts b/src/services/register-or-fetch-instance-doc.ts
index 3501e20de1..2c39502288 100644
--- a/src/services/register-or-fetch-instance-doc.ts
+++ b/src/services/register-or-fetch-instance-doc.ts
@@ -3,10 +3,16 @@ import { Instances } from '../models';
import { federationChart } from './chart';
import { genId } from '../misc/gen-id';
import { toPuny } from '../misc/convert-host';
+import { Cache } from '../misc/cache';
+
+const cache = new Cache<Instance>(1000 * 60 * 60);
export async function registerOrFetchInstanceDoc(host: string): Promise<Instance> {
host = toPuny(host);
+ const cached = cache.get(host);
+ if (cached) return cached;
+
const index = await Instances.findOne({ host });
if (index == null) {
@@ -19,8 +25,10 @@ export async function registerOrFetchInstanceDoc(host: string): Promise<Instance
federationChart.update(true);
+ cache.set(host, i);
return i;
} else {
+ cache.set(host, index);
return index;
}
}