mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-28 14:30:39 +01:00
remove unnecessary joins
This commit is contained in:
parent
7f287e0c3a
commit
ad1bacc2e5
2 changed files with 17 additions and 22 deletions
|
@ -141,24 +141,22 @@ export class AccountMoveService {
|
||||||
|
|
||||||
// follow the new account and unfollow the old one
|
// follow the new account and unfollow the old one
|
||||||
const proxy = await this.proxyAccountService.fetch();
|
const proxy = await this.proxyAccountService.fetch();
|
||||||
const followings = await this.followingsRepository.find({
|
const followings = await this.followingsRepository.findBy({
|
||||||
relations: {
|
|
||||||
follower: true,
|
|
||||||
},
|
|
||||||
where: {
|
|
||||||
followeeId: src.id,
|
followeeId: src.id,
|
||||||
followerHost: IsNull(), // follower is local
|
followerHost: IsNull(), // follower is local
|
||||||
followerId: proxy ? Not(proxy.id) : undefined,
|
followerId: proxy ? Not(proxy.id) : undefined,
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const followJobs: RelationshipJobData[] = [];
|
const followJobs: RelationshipJobData[] = [];
|
||||||
for (const following of followings) {
|
for (const following of followings) {
|
||||||
if (!following.follower) continue;
|
followJobs.push({ from: { id: following.followerId }, to: { id: dst.id } });
|
||||||
followJobs.push({ from: { id: following.follower.id }, to: { id: dst.id } });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrease following count instead of unfollowing.
|
// Decrease following count instead of unfollowing.
|
||||||
|
try {
|
||||||
await this.adjustFollowingCounts(followJobs.map(job => job.from.id), src);
|
await this.adjustFollowingCounts(followJobs.map(job => job.from.id), src);
|
||||||
|
} catch {
|
||||||
|
/* skip if any error happens */
|
||||||
|
}
|
||||||
|
|
||||||
// Should be queued because this can cause a number of follow per one move.
|
// Should be queued because this can cause a number of follow per one move.
|
||||||
this.queueService.createFollowJob(followJobs);
|
this.queueService.createFollowJob(followJobs);
|
||||||
|
@ -168,19 +166,14 @@ export class AccountMoveService {
|
||||||
public async copyBlocking(src: ThinUser, dst: ThinUser): Promise<void> {
|
public async copyBlocking(src: ThinUser, dst: ThinUser): Promise<void> {
|
||||||
// Followers shouldn't overlap with blockers, but the destination account, different from the blockee (i.e., old account), may have followed the local user before moving.
|
// Followers shouldn't overlap with blockers, but the destination account, different from the blockee (i.e., old account), may have followed the local user before moving.
|
||||||
// So block the destination account here.
|
// So block the destination account here.
|
||||||
const blockings = await this.blockingsRepository.find({ // FIXME: might be expensive
|
const srcBlockings = await this.blockingsRepository.findBy({ blockeeId: src.id });
|
||||||
relations: {
|
const dstBlockings = await this.blockingsRepository.findBy({ blockeeId: dst.id });
|
||||||
blocker: true
|
const blockerIds = dstBlockings.map(blocking => blocking.blockerId);
|
||||||
},
|
|
||||||
where: {
|
|
||||||
blockeeId: src.id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// reblock the destination account
|
// reblock the destination account
|
||||||
const blockJobs: RelationshipJobData[] = [];
|
const blockJobs: RelationshipJobData[] = [];
|
||||||
for (const blocking of blockings) {
|
for (const blocking of srcBlockings) {
|
||||||
if (!blocking.blocker) continue;
|
if (blockerIds.includes(blocking.blockerId)) continue; // skip if already blocked
|
||||||
blockJobs.push({ from: { id: blocking.blocker.id }, to: { id: dst.id } });
|
blockJobs.push({ from: { id: blocking.blockerId }, to: { id: dst.id } });
|
||||||
}
|
}
|
||||||
// no need to unblock the old account because it may be still functional
|
// no need to unblock the old account because it may be still functional
|
||||||
this.queueService.createBlockJob(blockJobs);
|
this.queueService.createBlockJob(blockJobs);
|
||||||
|
|
|
@ -765,8 +765,10 @@ export class ApInboxService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add target uri to movedToUri in order to indicate that the user has moved
|
// add target uri to movedToUri in order to indicate that the user has moved
|
||||||
|
if (oldAccount.movedToUri !== targetUri) {
|
||||||
await this.usersRepository.update(oldAccount.id, { movedToUri: targetUri });
|
await this.usersRepository.update(oldAccount.id, { movedToUri: targetUri });
|
||||||
oldAccount.movedToUri = targetUri;
|
oldAccount.movedToUri = targetUri;
|
||||||
|
}
|
||||||
|
|
||||||
// Move!
|
// Move!
|
||||||
await this.accountMoveService.move(oldAccount, newAccount);
|
await this.accountMoveService.move(oldAccount, newAccount);
|
||||||
|
|
Loading…
Reference in a new issue