1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-11-27 22:38:30 +09:00

perf(server): improve deliver performance

This commit is contained in:
syuilo 2022-03-26 17:43:08 +09:00
parent bc2c40a6ca
commit 3cac8e0f6f

View File

@ -1,6 +1,7 @@
import { Users, Followings } from '@/models/index.js'; import { Users, Followings } from '@/models/index.js';
import { ILocalUser, IRemoteUser, User } from '@/models/entities/user.js'; import { ILocalUser, IRemoteUser, User } from '@/models/entities/user.js';
import { deliver } from '@/queue/index.js'; import { deliver } from '@/queue/index.js';
import { IsNull, Not } from 'typeorm';
//#region types //#region types
interface IRecipe { interface IRecipe {
@ -82,16 +83,26 @@ export default class DeliverManager {
for (const recipe of this.recipes) { for (const recipe of this.recipes) {
if (isFollowers(recipe)) { if (isFollowers(recipe)) {
// followers deliver // followers deliver
const followers = await Followings.findBy({ // TODO: SELECT DISTINCT ON ("followerSharedInbox") "followerSharedInbox" みたいな問い合わせにすればよりパフォーマンス向上できそう
// ただ、sharedInboxがnullなリモートユーザーも稀におり、その対応ができなさそう
const followers = await Followings.find({
where: {
followeeId: this.actor.id, followeeId: this.actor.id,
}); followerHost: Not(IsNull()),
},
select: {
followerSharedInbox: true,
followerInbox: true,
},
}) as {
followerSharedInbox: string | null;
followerInbox: string;
}[];
for (const following of followers) { for (const following of followers) {
if (Followings.isRemoteFollower(following)) {
const inbox = following.followerSharedInbox || following.followerInbox; const inbox = following.followerSharedInbox || following.followerInbox;
inboxes.add(inbox); inboxes.add(inbox);
} }
}
} else if (isDirect(recipe)) { } else if (isDirect(recipe)) {
// direct deliver // direct deliver
const inbox = recipe.to.inbox; const inbox = recipe.to.inbox;