perf(server): reduce db query
This commit is contained in:
parent
78736c70f7
commit
6f2e93c6a1
6 changed files with 30 additions and 17 deletions
|
|
@ -10,6 +10,7 @@ import renderFollowUser from '@/remote/activitypub/renderer/follow-user.js';
|
|||
import { setResponseType } from '../activitypub.js';
|
||||
import { Users, Followings, UserProfiles } from '@/models/index.js';
|
||||
import { LessThan } from 'typeorm';
|
||||
import { userCache } from './cache.js';
|
||||
|
||||
export default async (ctx: Router.RouterContext) => {
|
||||
const userId = ctx.params.user;
|
||||
|
|
@ -27,11 +28,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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue