perf(server): reduce db query
This commit is contained in:
parent
78736c70f7
commit
6f2e93c6a1
6 changed files with 30 additions and 17 deletions
|
|
@ -15,6 +15,7 @@ import { Users, Notes } from '@/models/index.js';
|
|||
import { makePaginationQuery } from '../api/common/make-pagination-query.js';
|
||||
import { Brackets } from 'typeorm';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
import { userCache } from './cache.js';
|
||||
|
||||
export default async (ctx: Router.RouterContext) => {
|
||||
const userId = ctx.params.user;
|
||||
|
|
@ -35,11 +36,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