Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

全sharedInbox配信の最適化 #4933

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions src/services/suspend-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,38 @@ export async function sendDeleteActivity(user: IUser) {
// 知り得る全SharedInboxにDelete配信
const content = renderActivity(renderDelete(`${config.url}/users/${user._id}`, user));

const queue: string[] = [];

const followings = await Following.find({
$or: [
{ '_follower.sharedInbox': { $ne: null } },
{ '_followee.sharedInbox': { $ne: null } },
]
}, {
'_follower.sharedInbox': 1,
'_followee.sharedInbox': 1,
});

const inboxes = followings.map(x => x._follower.sharedInbox || x._followee.sharedInbox);

for (const inbox of inboxes) {
if (inbox != null && !queue.includes(inbox)) queue.push(inbox);
}
const results = await Following.aggregate([
{
$match: {
$or: [
{ '_follower.sharedInbox': { $ne: null } },
{ '_followee.sharedInbox': { $ne: null } }
]
}
},
{
$project: {
sharedInbox: {
$setUnion: [['$_follower.sharedInbox'], ['$_followee.sharedInbox']]
}
}
},
{
$unwind: '$sharedInbox'
},
{
$match: {
sharedInbox: { $ne: null }
}
},
{
$group: {
_id: '$sharedInbox',
}
}
]) as { _id: string }[];

for (const inbox of queue) {
for (const inbox of results.map(x => x._id)) {
deliver(user as any, content, inbox);
}
}
Expand Down
49 changes: 31 additions & 18 deletions src/services/unsuspend-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,38 @@ export async function doPostUnsuspend(user: IUser) {
// 知り得る全SharedInboxにUndo Delete配信
const content = renderActivity(renderUndo(renderDelete(`${config.url}/users/${user._id}`, user), user));

const queue: string[] = [];
const results = await Following.aggregate([
{
$match: {
$or: [
{ '_follower.sharedInbox': { $ne: null } },
{ '_followee.sharedInbox': { $ne: null } }
]
}
},
{
$project: {
sharedInbox: {
$setUnion: [['$_follower.sharedInbox'], ['$_followee.sharedInbox']]
}
}
},
{
$unwind: '$sharedInbox'
},
{
$match: {
sharedInbox: { $ne: null }
}
},
{
$group: {
_id: '$sharedInbox',
}
}
]) as { _id: string }[];

const followings = await Following.find({
$or: [
{ '_follower.sharedInbox': { $ne: null } },
{ '_followee.sharedInbox': { $ne: null } },
]
}, {
'_follower.sharedInbox': 1,
'_followee.sharedInbox': 1,
});

const inboxes = followings.map(x => x._follower.sharedInbox || x._followee.sharedInbox);

for (const inbox of inboxes) {
if (inbox != null && !queue.includes(inbox)) queue.push(inbox);
}

for (const inbox of queue) {
for (const inbox of results.map(x => x._id)) {
deliver(user as any, content, inbox);
}
}
Expand Down
Loading