Skip to content
Snippets Groups Projects
Unverified Commit 1033e8e5 authored by Johann150's avatar Johann150 Committed by GitHub
Browse files

fix(federation): avoid duplicate activity delivery (#8429)

* prefer shared inbox over individual inbox

* no new shared inbox for direct recipes

* fix type error
parent f7030d4a
No related branches found
No related tags found
No related merge requests found
...@@ -79,37 +79,46 @@ export default class DeliverManager { ...@@ -79,37 +79,46 @@ export default class DeliverManager {
const inboxes = new Set<string>(); const inboxes = new Set<string>();
// build inbox list /*
for (const recipe of this.recipes) { build inbox list
if (isFollowers(recipe)) {
// followers deliver Process follower recipes first to avoid duplication when processing
// TODO: SELECT DISTINCT ON ("followerSharedInbox") "followerSharedInbox" みたいな問い合わせにすればよりパフォーマンス向上できそう direct recipes later.
// ただ、sharedInboxがnullなリモートユーザーも稀におり、その対応ができなさそう? */
const followers = await Followings.find({ if (this.recipes.some(r => isFollowers(r)) {
where: { // followers deliver
followeeId: this.actor.id, // TODO: SELECT DISTINCT ON ("followerSharedInbox") "followerSharedInbox" みたいな問い合わせにすればよりパフォーマンス向上できそう
followerHost: Not(IsNull()), // ただ、sharedInboxがnullなリモートユーザーも稀におり、その対応ができなさそう?
}, const followers = await Followings.find({
select: { where: {
followerSharedInbox: true, followeeId: this.actor.id,
followerInbox: true, followerHost: Not(IsNull()),
}, },
}) as { select: {
followerSharedInbox: string | null; followerSharedInbox: true,
followerInbox: string; followerInbox: true,
}[]; },
}) as {
for (const following of followers) { followerSharedInbox: string | null;
const inbox = following.followerSharedInbox || following.followerInbox; followerInbox: string;
inboxes.add(inbox); }[];
}
} else if (isDirect(recipe)) { for (const following of followers) {
// direct deliver const inbox = following.followerSharedInbox || following.followerInbox;
const inbox = recipe.to.inbox; inboxes.add(inbox);
if (inbox) inboxes.add(inbox);
} }
} }
this.recipes.filter((recipe): recipe is IDirectRecipe => {
// followers recipes have already been processed
isDirect(recipe)
// check that shared inbox has not been added yet
&& !(recipe.to.sharedInbox && inboxes.has(recipe.to.sharedInbox))
// check that they actually have an inbox
&& recipe.to.inbox
})
.forEach(recipe => inboxes.add(recipe.to.inbox));
// deliver // deliver
for (const inbox of inboxes) { for (const inbox of inboxes) {
deliver(this.actor, this.activity, inbox); deliver(this.actor, this.activity, inbox);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment