要らん

This commit is contained in:
syuilo 2022-03-22 00:35:36 +09:00
parent 3da9d20686
commit 57be66a94e
3 changed files with 6 additions and 15 deletions

View File

@ -18,7 +18,6 @@ import { ILocalUser, User } from '@/models/entities/user.js';
import { In } from 'typeorm'; import { In } from 'typeorm';
import { renderLike } from '@/remote/activitypub/renderer/like.js'; import { renderLike } from '@/remote/activitypub/renderer/like.js';
import { getUserKeypair } from '@/misc/keypair-store.js'; import { getUserKeypair } from '@/misc/keypair-store.js';
import { noteCache, userCache } from './activitypub/cache.js';
// Init router // Init router
const router = new Router(); const router = new Router();
@ -66,13 +65,11 @@ router.post('/users/:user/inbox', json(), inbox);
router.get('/notes/:note', async (ctx, next) => { router.get('/notes/:note', async (ctx, next) => {
if (!isActivityPubReq(ctx)) return await next(); if (!isActivityPubReq(ctx)) return await next();
// TODO: typeorm 3.0にしたら .then(x => x || null) は消せる const note = await Notes.findOne({
// nginxとかでキャッシュしてくれそうだからそもそもnode側でのキャッシュ不要かも
const note = await noteCache.fetch(ctx.params.note, () => Notes.findOne({
id: ctx.params.note, id: ctx.params.note,
visibility: In(['public' as const, 'home' as const]), visibility: In(['public' as const, 'home' as const]),
localOnly: false, localOnly: false,
}).then(x => x || null)); });
if (note == null) { if (note == null) {
ctx.status = 404; ctx.status = 404;
@ -167,13 +164,11 @@ router.get('/users/:user', async (ctx, next) => {
const userId = ctx.params.user; const userId = ctx.params.user;
// TODO: typeorm 3.0にしたら .then(x => x || null) は消せる const user = await Users.findOne({
// nginxとかでキャッシュしてくれそうだからそもそもnode側でのキャッシュ不要かも
const user = await userCache.fetch(userId, () => Users.findOne({
id: userId, id: userId,
host: null, host: null,
isSuspended: false, isSuspended: false,
}).then(x => x || null)); });
await userInfo(ctx, user); await userInfo(ctx, user);
}); });

View File

@ -1,6 +1,4 @@
import { Cache } from "@/misc/cache.js"; import { Cache } from "@/misc/cache.js";
import { Note } from "@/models/entities/note.js";
import { User } from "@/models/entities/user.js"; import { User } from "@/models/entities/user.js";
export const userCache = new Cache<User | null>(1000 * 60 * 30); export const userCache = new Cache<User | null>(1000 * 60 * 30);
export const noteCache = new Cache<Note | null>(1000 * 60 * 30);

View File

@ -5,16 +5,14 @@ import renderOrderedCollection from '@/remote/activitypub/renderer/ordered-colle
import { setResponseType } from '../activitypub.js'; import { setResponseType } from '../activitypub.js';
import renderNote from '@/remote/activitypub/renderer/note.js'; import renderNote from '@/remote/activitypub/renderer/note.js';
import { Users, Notes, UserNotePinings } from '@/models/index.js'; import { Users, Notes, UserNotePinings } from '@/models/index.js';
import { userCache } from './cache.js';
export default async (ctx: Router.RouterContext) => { export default async (ctx: Router.RouterContext) => {
const userId = ctx.params.user; const userId = ctx.params.user;
// TODO: typeorm 3.0にしたら .then(x => x || null) は消せる const user = await Users.findOne({
const user = await userCache.fetch(userId, () => Users.findOne({
id: userId, id: userId,
host: null, host: null,
}).then(x => x || null)); });
if (user == null) { if (user == null) {
ctx.status = 404; ctx.status = 404;