refactor
This commit is contained in:
parent
6f5282058f
commit
22b56ac65c
|
@ -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);
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -44,13 +44,8 @@ export const paramDef = {
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
// eslint-disable-next-line import/no-default-export
|
||||||
export default define(meta, paramDef, async (ps, user) => {
|
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 = {
|
const query = {
|
||||||
noteId: note.id,
|
noteId: ps.noteId,
|
||||||
} as DeepPartial<NoteReaction>;
|
} as DeepPartial<NoteReaction>;
|
||||||
|
|
||||||
if (ps.type) {
|
if (ps.type) {
|
||||||
|
|
|
@ -70,7 +70,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
}).then(x => AbuseUserReports.findOneOrFail(x.identifiers[0]));
|
}).then(x => AbuseUserReports.findOneOrFail(x.identifiers[0]));
|
||||||
|
|
||||||
// Publish event to moderators
|
// Publish event to moderators
|
||||||
setTimeout(async () => {
|
setImmediate(async () => {
|
||||||
const moderators = await Users.find({
|
const moderators = await Users.find({
|
||||||
where: [{
|
where: [{
|
||||||
isAdmin: true,
|
isAdmin: true,
|
||||||
|
@ -94,5 +94,5 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
sanitizeHtml(ps.comment),
|
sanitizeHtml(ps.comment),
|
||||||
sanitizeHtml(ps.comment));
|
sanitizeHtml(ps.comment));
|
||||||
}
|
}
|
||||||
}, 1);
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue