perf(server): refactor and performance improvements
This commit is contained in:
@@ -38,8 +38,6 @@ import { endedPollNotificationQueue } from '@/queue/queues.js';
|
||||
import { Cache } from '@/misc/cache.js';
|
||||
import { UserProfile } from '@/models/entities/user-profile.js';
|
||||
|
||||
const usersCache = new Cache<MinimumUser>(Infinity);
|
||||
|
||||
const mutedWordsCache = new Cache<{ userId: UserProfile['userId']; mutedWords: UserProfile['mutedWords']; }[]>(1000 * 60 * 5);
|
||||
|
||||
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention';
|
||||
@@ -212,7 +210,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
|
||||
tags = tags.filter(tag => Array.from(tag || '').length <= 128).splice(0, 32);
|
||||
|
||||
if (data.reply && (user.id !== data.reply.userId) && !mentionedUsers.some(u => u.id === data.reply!.userId)) {
|
||||
mentionedUsers.push(await usersCache.fetch(data.reply.userId, () => Users.findOneOrFail(data.reply!.userId)));
|
||||
mentionedUsers.push(await Users.findOneOrFail(data.reply!.userId));
|
||||
}
|
||||
|
||||
if (data.visibility === 'specified') {
|
||||
@@ -225,7 +223,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
|
||||
}
|
||||
|
||||
if (data.reply && !data.visibleUsers.some(x => x.id === data.reply!.userId)) {
|
||||
data.visibleUsers.push(await usersCache.fetch(data.reply.userId, () => Users.findOneOrFail(data.reply!.userId)));
|
||||
data.visibleUsers.push(await Users.findOneOrFail(data.reply!.userId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import { Brackets, In } from 'typeorm';
|
||||
* @param user 投稿者
|
||||
* @param note 投稿
|
||||
*/
|
||||
export default async function(user: User, note: Note, quiet = false) {
|
||||
export default async function(user: { id: User['id']; uri: User['uri']; host: User['host']; }, note: Note, quiet = false) {
|
||||
const deletedAt = new Date();
|
||||
|
||||
// この投稿を除く指定したユーザーによる指定したノートのリノートが存在しないとき
|
||||
@@ -131,7 +131,7 @@ async function getMentionedRemoteUsers(note: Note) {
|
||||
}) as IRemoteUser[];
|
||||
}
|
||||
|
||||
async function deliverToConcerned(user: ILocalUser, note: Note, content: any) {
|
||||
async function deliverToConcerned(user: { id: ILocalUser['id']; host: null; }, note: Note, content: any) {
|
||||
deliverToFollowers(user, content);
|
||||
deliverToRelays(user, content);
|
||||
const remoteUsers = await getMentionedRemoteUsers(note);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { publishNoteStream } from '@/services/stream.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { CacheableUser, User } from '@/models/entities/user.js';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
import { PollVotes, NoteWatchings, Polls, Blockings } from '@/models/index.js';
|
||||
import { Not } from 'typeorm';
|
||||
import { genId } from '@/misc/gen-id.js';
|
||||
import { createNotification } from '../../create-notification.js';
|
||||
|
||||
export default async function(user: User, note: Note, choice: number) {
|
||||
export default async function(user: CacheableUser, note: Note, choice: number) {
|
||||
const poll = await Polls.findOne(note.id);
|
||||
|
||||
if (poll == null) throw new Error('poll not found');
|
||||
|
||||
Reference in New Issue
Block a user