perf(server): reduce db query
This commit is contained in:
parent
bff99d564d
commit
3da9d20686
@ -49,7 +49,7 @@ export default async (job: Bull.Job<InboxJobData>): Promise<string> => {
|
|||||||
// HTTP-Signature keyIdを元にDBから取得
|
// HTTP-Signature keyIdを元にDBから取得
|
||||||
let authUser: {
|
let authUser: {
|
||||||
user: CacheableRemoteUser;
|
user: CacheableRemoteUser;
|
||||||
key?: UserPublickey;
|
key: UserPublickey | null;
|
||||||
} | null = await dbResolver.getAuthUserFromKeyId(signature.keyId);
|
} | null = await dbResolver.getAuthUserFromKeyId(signature.keyId);
|
||||||
|
|
||||||
// keyIdでわからなければ、activity.actorを元にDBから取得 || activity.actorを元にリモートから取得
|
// keyIdでわからなければ、activity.actorを元にDBから取得 || activity.actorを元にリモートから取得
|
||||||
|
@ -10,6 +10,7 @@ import { resolvePerson } from './models/person.js';
|
|||||||
import { Cache } from '@/misc/cache.js';
|
import { Cache } from '@/misc/cache.js';
|
||||||
|
|
||||||
const publicKeyCache = new Cache<(UserPublickey & { user: User }) | null>(Infinity);
|
const publicKeyCache = new Cache<(UserPublickey & { user: User }) | null>(Infinity);
|
||||||
|
const publicKeyByUserIdCache = new Cache<UserPublickey | null>(Infinity);
|
||||||
|
|
||||||
export default class DbResolver {
|
export default class DbResolver {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -107,14 +108,13 @@ export default class DbResolver {
|
|||||||
*/
|
*/
|
||||||
public async getAuthUserFromApId(uri: string): Promise<{
|
public async getAuthUserFromApId(uri: string): Promise<{
|
||||||
user: CacheableRemoteUser;
|
user: CacheableRemoteUser;
|
||||||
key?: UserPublickey;
|
key: UserPublickey | null;
|
||||||
} | null> {
|
} | null> {
|
||||||
const user = await resolvePerson(uri) as CacheableRemoteUser;
|
const user = await resolvePerson(uri) as CacheableRemoteUser;
|
||||||
|
|
||||||
if (user == null) return null;
|
if (user == null) return null;
|
||||||
|
|
||||||
// TODO: cache
|
const key = await publicKeyByUserIdCache.fetch(user.id, () => UserPublickeys.findOne(user.id).then(x => x || null), v => v != null); // TODO: typeorm 3.0 にしたら.then(x => x || null)は消せる
|
||||||
const key = await UserPublickeys.findOne(user.id);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user,
|
user,
|
||||||
|
Loading…
Reference in New Issue
Block a user