perf(server): refactor and performance improvements
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
import { Cache } from "@/misc/cache.js";
|
||||
import { User } from "@/models/entities/user.js";
|
||||
|
||||
export const userCache = new Cache<User | null>(1000 * 60 * 30);
|
@@ -10,7 +10,6 @@ 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;
|
||||
@@ -28,11 +27,10 @@ export default async (ctx: Router.RouterContext) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: typeorm 3.0にしたら .then(x => x || null) は消せる
|
||||
const user = await userCache.fetch(userId, () => Users.findOne({
|
||||
const user = await Users.findOne({
|
||||
id: userId,
|
||||
host: null,
|
||||
}).then(x => x || null));
|
||||
});
|
||||
|
||||
if (user == null) {
|
||||
ctx.status = 404;
|
||||
|
@@ -11,7 +11,6 @@ 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;
|
||||
@@ -29,11 +28,10 @@ export default async (ctx: Router.RouterContext) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: typeorm 3.0にしたら .then(x => x || null) は消せる
|
||||
const user = await userCache.fetch(userId, () => Users.findOne({
|
||||
const user = await Users.findOne({
|
||||
id: userId,
|
||||
host: null,
|
||||
}).then(x => x || null));
|
||||
});
|
||||
|
||||
if (user == null) {
|
||||
ctx.status = 404;
|
||||
|
@@ -15,7 +15,6 @@ 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;
|
||||
@@ -36,11 +35,10 @@ export default async (ctx: Router.RouterContext) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: typeorm 3.0にしたら .then(x => x || null) は消せる
|
||||
const user = await userCache.fetch(userId, () => Users.findOne({
|
||||
const user = await Users.findOne({
|
||||
id: userId,
|
||||
host: null,
|
||||
}).then(x => x || null));
|
||||
});
|
||||
|
||||
if (user == null) {
|
||||
ctx.status = 404;
|
||||
|
Reference in New Issue
Block a user