perf(server): reduce db query

This commit is contained in:
syuilo
2022-03-21 05:21:37 +09:00
parent 78736c70f7
commit 6f2e93c6a1
6 changed files with 30 additions and 17 deletions

View File

@ -11,6 +11,7 @@ import { setResponseType } from '../activitypub.js';
import { Users, Followings, UserProfiles } from '@/models/index.js';
import { LessThan, FindConditions } from 'typeorm';
import { Following } from '@/models/entities/following.js';
import { userCache } from './cache.js';
export default async (ctx: Router.RouterContext) => {
const userId = ctx.params.user;
@ -28,11 +29,11 @@ export default async (ctx: Router.RouterContext) => {
return;
}
// Verify user
const user = await Users.findOne({
// TODO: typeorm 3.0にしたら .then(x => x || null) は消せる
const user = await userCache.fetch(userId, () => Users.findOne({
id: userId,
host: null,
});
}).then(x => x || null));
if (user == null) {
ctx.status = 404;