From 22b56ac65c306305964a0b158510f975375fb635 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 25 Mar 2022 13:11:52 +0900 Subject: [PATCH] refactor --- packages/backend/src/server/activitypub/cache.ts | 2 -- packages/backend/src/server/activitypub/featured.ts | 6 ++---- .../backend/src/server/api/endpoints/notes/reactions.ts | 7 +------ .../backend/src/server/api/endpoints/users/report-abuse.ts | 4 ++-- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/server/activitypub/cache.ts b/packages/backend/src/server/activitypub/cache.ts index 00199ee253..eb20d00787 100644 --- a/packages/backend/src/server/activitypub/cache.ts +++ b/packages/backend/src/server/activitypub/cache.ts @@ -1,6 +1,4 @@ import { Cache } from "@/misc/cache.js"; -import { Note } from "@/models/entities/note.js"; import { User } from "@/models/entities/user.js"; export const userCache = new Cache(1000 * 60 * 30); -export const noteCache = new Cache(1000 * 60 * 30); diff --git a/packages/backend/src/server/activitypub/featured.ts b/packages/backend/src/server/activitypub/featured.ts index d06a28a9ca..5dc8792a9a 100644 --- a/packages/backend/src/server/activitypub/featured.ts +++ b/packages/backend/src/server/activitypub/featured.ts @@ -5,16 +5,14 @@ import renderOrderedCollection from '@/remote/activitypub/renderer/ordered-colle import { setResponseType } from '../activitypub.js'; import renderNote from '@/remote/activitypub/renderer/note.js'; import { Users, Notes, UserNotePinings } from '@/models/index.js'; -import { userCache } from './cache.js'; export default async (ctx: Router.RouterContext) => { const userId = ctx.params.user; - // 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; diff --git a/packages/backend/src/server/api/endpoints/notes/reactions.ts b/packages/backend/src/server/api/endpoints/notes/reactions.ts index 43e5d1ef6f..70db12fb14 100644 --- a/packages/backend/src/server/api/endpoints/notes/reactions.ts +++ b/packages/backend/src/server/api/endpoints/notes/reactions.ts @@ -44,13 +44,8 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export export default define(meta, paramDef, async (ps, user) => { - const note = await getNote(ps.noteId).catch(e => { - if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); - throw e; - }); - const query = { - noteId: note.id, + noteId: ps.noteId, } as DeepPartial; if (ps.type) { diff --git a/packages/backend/src/server/api/endpoints/users/report-abuse.ts b/packages/backend/src/server/api/endpoints/users/report-abuse.ts index e091b8e1b1..57f6a465fe 100644 --- a/packages/backend/src/server/api/endpoints/users/report-abuse.ts +++ b/packages/backend/src/server/api/endpoints/users/report-abuse.ts @@ -70,7 +70,7 @@ export default define(meta, paramDef, async (ps, me) => { }).then(x => AbuseUserReports.findOneOrFail(x.identifiers[0])); // Publish event to moderators - setTimeout(async () => { + setImmediate(async () => { const moderators = await Users.find({ where: [{ isAdmin: true, @@ -94,5 +94,5 @@ export default define(meta, paramDef, async (ps, me) => { sanitizeHtml(ps.comment), sanitizeHtml(ps.comment)); } - }, 1); + }); });