forked from FoundKeyGang/FoundKey
server: optimise follower inboxes query
Use the distinct query thingy so we don't have to make the Set work so hard. This is also uniform code with the "everyone" above so should hopefully be easier to understand.
This commit is contained in:
parent
b1bb5b28c5
commit
8979e779da
1 changed files with 11 additions and 19 deletions
|
@ -119,26 +119,18 @@ export default class DeliverManager {
|
||||||
|
|
||||||
if (this.recipes.some(r => isFollowers(r))) {
|
if (this.recipes.some(r => isFollowers(r))) {
|
||||||
// followers deliver
|
// followers deliver
|
||||||
// TODO: SELECT DISTINCT ON ("followerSharedInbox") "followerSharedInbox" みたいな問い合わせにすればよりパフォーマンス向上できそう
|
const followers = await Followings.createQueryBuilder('followings')
|
||||||
// ただ、sharedInboxがnullなリモートユーザーも稀におり、その対応ができなさそう?
|
// return either the shared inbox (if available) or the individual inbox
|
||||||
const followers = await Followings.find({
|
.select('COALESCE(followings.followerSharedInbox, followings.followerInbox)', 'inbox')
|
||||||
where: {
|
// so we don't have to make our inboxes Set work as hard
|
||||||
followeeId: this.actor.id,
|
.distinct(true)
|
||||||
followerHost: Not(IsNull()),
|
// ...for the specific actors followers
|
||||||
},
|
.where('followings.followeeId = :actorId', { actorId: this.actor.id })
|
||||||
select: {
|
// don't deliver to ourselves
|
||||||
followerSharedInbox: true,
|
.andWhere('followings.followerHost IS NOT NULL')
|
||||||
followerInbox: true,
|
.getRawMany();
|
||||||
},
|
|
||||||
}) as {
|
|
||||||
followerSharedInbox: string | null;
|
|
||||||
followerInbox: string;
|
|
||||||
}[];
|
|
||||||
|
|
||||||
for (const following of followers) {
|
followers.forEach(({ inbox }) => inboxes.add(inbox));
|
||||||
const inbox = following.followerSharedInbox || following.followerInbox;
|
|
||||||
inboxes.add(inbox);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.recipes.filter((recipe): recipe is IDirectRecipe =>
|
this.recipes.filter((recipe): recipe is IDirectRecipe =>
|
||||||
|
|
Loading…
Reference in a new issue