summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-03-22 15:14:54 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-03-22 15:14:54 +0900
commit7c3086e9d9508d5df03d7859932c766a26b9664e (patch)
treeddb4da56c3a14fdb6115c91290dd58d1111ef51b /src/misc
parenttweak cache lifetime (diff)
downloadsharkey-7c3086e9d9508d5df03d7859932c766a26b9664e.tar.gz
sharkey-7c3086e9d9508d5df03d7859932c766a26b9664e.tar.bz2
sharkey-7c3086e9d9508d5df03d7859932c766a26b9664e.zip
perf(server): Cache user keypair
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/keypair-store.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/misc/keypair-store.ts b/src/misc/keypair-store.ts
new file mode 100644
index 0000000000..43f451110c
--- /dev/null
+++ b/src/misc/keypair-store.ts
@@ -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));
+}