From 57be66a94e6750223e5a63eb450a972b258e11b1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 22 Mar 2022 00:35:36 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A6=81=E3=82=89=E3=82=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/activitypub.ts | 13 ++++--------- packages/backend/src/server/activitypub/cache.ts | 2 -- packages/backend/src/server/activitypub/featured.ts | 6 ++---- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/server/activitypub.ts b/packages/backend/src/server/activitypub.ts index c0a9b3772..d4871ca9d 100644 --- a/packages/backend/src/server/activitypub.ts +++ b/packages/backend/src/server/activitypub.ts @@ -18,7 +18,6 @@ import { ILocalUser, User } from '@/models/entities/user.js'; import { In } from 'typeorm'; import { renderLike } from '@/remote/activitypub/renderer/like.js'; import { getUserKeypair } from '@/misc/keypair-store.js'; -import { noteCache, userCache } from './activitypub/cache.js'; // Init router const router = new Router(); @@ -66,13 +65,11 @@ router.post('/users/:user/inbox', json(), inbox); router.get('/notes/:note', async (ctx, next) => { if (!isActivityPubReq(ctx)) return await next(); - // TODO: typeorm 3.0にしたら .then(x => x || null) は消せる - // nginxとかでキャッシュしてくれそうだからそもそもnode側でのキャッシュ不要かも? - const note = await noteCache.fetch(ctx.params.note, () => Notes.findOne({ + const note = await Notes.findOne({ id: ctx.params.note, visibility: In(['public' as const, 'home' as const]), localOnly: false, - }).then(x => x || null)); + }); if (note == null) { ctx.status = 404; @@ -167,13 +164,11 @@ router.get('/users/:user', async (ctx, next) => { const userId = ctx.params.user; - // TODO: typeorm 3.0にしたら .then(x => x || null) は消せる - // nginxとかでキャッシュしてくれそうだからそもそもnode側でのキャッシュ不要かも? - const user = await userCache.fetch(userId, () => Users.findOne({ + const user = await Users.findOne({ id: userId, host: null, isSuspended: false, - }).then(x => x || null)); + }); await userInfo(ctx, user); }); diff --git a/packages/backend/src/server/activitypub/cache.ts b/packages/backend/src/server/activitypub/cache.ts index 00199ee25..eb20d0078 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 d06a28a9c..5dc8792a9 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;