Improve server performance
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user