diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-03-18 10:49:14 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-03-18 10:52:54 +0900 |
| commit | 8aa089178a54559cbc4e4fe84a618fc7535f178c (patch) | |
| tree | 5f8cb6d5c51a37f4b667f7cd76d836f500cee1b4 /src/services/register-or-fetch-instance-doc.ts | |
| parent | Improve API performance (diff) | |
| download | sharkey-8aa089178a54559cbc4e4fe84a618fc7535f178c.tar.gz sharkey-8aa089178a54559cbc4e4fe84a618fc7535f178c.tar.bz2 sharkey-8aa089178a54559cbc4e4fe84a618fc7535f178c.zip | |
Improve server performance
Diffstat (limited to 'src/services/register-or-fetch-instance-doc.ts')
| -rw-r--r-- | src/services/register-or-fetch-instance-doc.ts | 8 |
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; } } |