summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/AccountMoveService.ts
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-06-12 15:42:39 +0000
committerHazelnoot <acomputerdog@gmail.com>2025-06-12 15:42:39 +0000
commit55551a5a8a3a218b9f56491f2dbe3f70e3ef3556 (patch)
tree927f789e18162a91da0144356d040995864613ee /packages/backend/src/core/AccountMoveService.ts
parentmerge: Enforce DM visibility in generateVisibilityQuery (!1108) (diff)
parentfix relations in MastodonDataService.ts (diff)
downloadsharkey-55551a5a8a3a218b9f56491f2dbe3f70e3ef3556.tar.gz
sharkey-55551a5a8a3a218b9f56491f2dbe3f70e3ef3556.tar.bz2
sharkey-55551a5a8a3a218b9f56491f2dbe3f70e3ef3556.zip
merge: Avoid more N+1 queries in NoteEntityService and UserEntityService (!1099)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1099 Approved-by: dakkar <dakkar@thenautilus.net> Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/core/AccountMoveService.ts')
-rw-r--r--packages/backend/src/core/AccountMoveService.ts24
1 files changed, 11 insertions, 13 deletions
diff --git a/packages/backend/src/core/AccountMoveService.ts b/packages/backend/src/core/AccountMoveService.ts
index 738026f753..e107f02796 100644
--- a/packages/backend/src/core/AccountMoveService.ts
+++ b/packages/backend/src/core/AccountMoveService.ts
@@ -26,6 +26,7 @@ import PerUserFollowingChart from '@/core/chart/charts/per-user-following.js';
import { SystemAccountService } from '@/core/SystemAccountService.js';
import { RoleService } from '@/core/RoleService.js';
import { AntennaService } from '@/core/AntennaService.js';
+import { CacheService } from '@/core/CacheService.js';
@Injectable()
export class AccountMoveService {
@@ -68,6 +69,7 @@ export class AccountMoveService {
private systemAccountService: SystemAccountService,
private roleService: RoleService,
private antennaService: AntennaService,
+ private readonly cacheService: CacheService,
) {
}
@@ -107,12 +109,10 @@ export class AccountMoveService {
this.globalEventService.publishMainStream(src.id, 'meUpdated', iObj);
// Unfollow after 24 hours
- const followings = await this.followingsRepository.findBy({
- followerId: src.id,
- });
- this.queueService.createDelayedUnfollowJob(followings.map(following => ({
+ const followings = await this.cacheService.userFollowingsCache.fetch(src.id);
+ this.queueService.createDelayedUnfollowJob(Array.from(followings.keys()).map(followeeId => ({
from: { id: src.id },
- to: { id: following.followeeId },
+ to: { id: followeeId },
})), process.env.NODE_ENV === 'test' ? 10000 : 1000 * 60 * 60 * 24);
await this.postMoveProcess(src, dst);
@@ -138,11 +138,9 @@ export class AccountMoveService {
// follow the new account
const proxy = await this.systemAccountService.fetch('proxy');
- const followings = await this.followingsRepository.findBy({
- followeeId: src.id,
- followerHost: IsNull(), // follower is local
- followerId: Not(proxy.id),
- });
+ const followings = await this.cacheService.userFollowersCache.fetch(src.id)
+ .then(fs => Array.from(fs.values())
+ .filter(f => f.followerHost == null && f.followerId !== proxy.id));
const followJobs = followings.map(following => ({
from: { id: following.followerId },
to: { id: dst.id },
@@ -318,9 +316,9 @@ export class AccountMoveService {
await this.usersRepository.decrement({ id: In(localFollowerIds) }, 'followingCount', 1);
// Decrease follower counts of local followees by 1.
- const oldFollowings = await this.followingsRepository.findBy({ followerId: oldAccount.id });
- if (oldFollowings.length > 0) {
- await this.usersRepository.decrement({ id: In(oldFollowings.map(following => following.followeeId)) }, 'followersCount', 1);
+ const oldFollowings = await this.cacheService.userFollowingsCache.fetch(oldAccount.id);
+ if (oldFollowings.size > 0) {
+ await this.usersRepository.decrement({ id: In(Array.from(oldFollowings.keys())) }, 'followersCount', 1);
}
// Update instance stats by decreasing remote followers count by the number of local followers who were following the old account.