From 7c3086e9d9508d5df03d7859932c766a26b9664e Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 22 Mar 2021 15:14:54 +0900 Subject: perf(server): Cache user keypair --- src/remote/activitypub/renderer/index.ts | 6 ++---- src/remote/activitypub/renderer/person.ts | 5 +++-- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src/remote/activitypub/renderer') diff --git a/src/remote/activitypub/renderer/index.ts b/src/remote/activitypub/renderer/index.ts index e74affdadf..4c33fdafb1 100644 --- a/src/remote/activitypub/renderer/index.ts +++ b/src/remote/activitypub/renderer/index.ts @@ -3,7 +3,7 @@ import { v4 as uuid } from 'uuid'; import { IActivity } from '../type'; import { LdSignature } from '../misc/ld-signature'; import { ILocalUser } from '../../../models/entities/user'; -import { UserKeypairs } from '../../../models'; +import { getUserKeypair } from '../../../misc/keypair-store'; export const renderActivity = (x: any): IActivity | null => { if (x == null) return null; @@ -23,9 +23,7 @@ export const renderActivity = (x: any): IActivity | null => { export const attachLdSignature = async (activity: any, user: ILocalUser): Promise => { if (activity == null) return null; - const keypair = await UserKeypairs.findOneOrFail({ - userId: user.id - }); + const keypair = await getUserKeypair(user.id); const obj = { // as non-standards diff --git a/src/remote/activitypub/renderer/person.ts b/src/remote/activitypub/renderer/person.ts index 4907e3bc6f..479e6d76bf 100644 --- a/src/remote/activitypub/renderer/person.ts +++ b/src/remote/activitypub/renderer/person.ts @@ -8,7 +8,8 @@ import { getEmojis } from './note'; import renderEmoji from './emoji'; import { IIdentifier } from '../models/identifier'; import renderHashtag from './hashtag'; -import { DriveFiles, UserProfiles, UserKeypairs } from '../../../models'; +import { DriveFiles, UserProfiles } from '../../../models'; +import { getUserKeypair } from '../../../misc/keypair-store'; export async function renderPerson(user: ILocalUser) { const id = `${config.url}/users/${user.id}`; @@ -49,7 +50,7 @@ export async function renderPerson(user: ILocalUser) { ...hashtagTags, ]; - const keypair = await UserKeypairs.findOneOrFail(user.id); + const keypair = await getUserKeypair(user.id); const person = { type: isSystem ? 'Application' : user.isBot ? 'Service' : 'Person', -- cgit v1.2.3-freya