perf(server): Cache user keypair

This commit is contained in:
syuilo 2021-03-22 15:14:54 +09:00
parent 202e943d55
commit 7c3086e9d9
5 changed files with 21 additions and 15 deletions

10
src/misc/keypair-store.ts Normal file
View file

@ -0,0 +1,10 @@
import { UserKeypairs } from '../models';
import { User } from '../models/entities/user';
import { UserKeypair } from '../models/entities/user-keypair';
import { Cache } from './cache';
const cache = new Cache<UserKeypair>(Infinity);
export async function getUserKeypair(userId: User['id']): Promise<UserKeypair> {
return await cache.fetch(userId, async () => await UserKeypairs.findOneOrFail(userId));
}