summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/entities
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-05-28 02:02:27 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-06-04 10:45:18 -0400
commit23302fe7d8de4923f4748f6c64d39e3f57c9d98f (patch)
tree5bacd47112365bea340aff078fa2138e21803c7b /packages/backend/src/core/entities
parentadd targetInstance to abuse report schema (diff)
downloadsharkey-23302fe7d8de4923f4748f6c64d39e3f57c9d98f.tar.gz
sharkey-23302fe7d8de4923f4748f6c64d39e3f57c9d98f.tar.bz2
sharkey-23302fe7d8de4923f4748f6c64d39e3f57c9d98f.zip
add relation from user->user_profile to speed up UserEntityService.pack and packMany
Diffstat (limited to 'packages/backend/src/core/entities')
-rw-r--r--packages/backend/src/core/entities/UserEntityService.ts34
1 files changed, 27 insertions, 7 deletions
diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts
index 3524119ba1..326baaefd4 100644
--- a/packages/backend/src/core/entities/UserEntityService.ts
+++ b/packages/backend/src/core/entities/UserEntityService.ts
@@ -487,7 +487,10 @@ export class UserEntityService implements OnModuleInit {
includeSecrets: false,
}, options);
- const user = typeof src === 'object' ? src : await this.usersRepository.findOneByOrFail({ id: src });
+ const user = typeof src === 'object' ? src : await this.usersRepository.findOneOrFail({
+ where: { id: src },
+ relations: { userProfile: true },
+ });
// migration
if (user.avatarId != null && user.avatarUrl === null) {
@@ -521,7 +524,7 @@ export class UserEntityService implements OnModuleInit {
const iAmModerator = me ? await this.roleService.isModerator(me as MiUser) : false;
const profile = isDetailed
- ? (opts.userProfile ?? await this.userProfilesRepository.findOneByOrFail({ userId: user.id }))
+ ? (opts.userProfile ?? user.userProfile ?? await this.userProfilesRepository.findOneByOrFail({ userId: user.id }))
: null;
let relation: UserRelation | null = null;
@@ -556,7 +559,7 @@ export class UserEntityService implements OnModuleInit {
}
}
- const mastoapi = !isDetailed ? opts.userProfile ?? await this.userProfilesRepository.findOneByOrFail({ userId: user.id }) : null;
+ const mastoapi = !isDetailed ? opts.userProfile ?? user.userProfile ?? await this.userProfilesRepository.findOneByOrFail({ userId: user.id }) : null;
const followingCount = profile == null ? null :
(profile.followingVisibility === 'public') || isMe || iAmModerator ? user.followingCount :
@@ -785,8 +788,13 @@ export class UserEntityService implements OnModuleInit {
const _users = users.filter((user): user is MiUser => typeof user !== 'string');
if (_users.length !== users.length) {
_users.push(
- ...await this.usersRepository.findBy({
- id: In(users.filter((user): user is string => typeof user === 'string')),
+ ...await this.usersRepository.find({
+ where: {
+ id: In(users.filter((user): user is string => typeof user === 'string')),
+ },
+ relations: {
+ userProfile: true,
+ },
}),
);
}
@@ -800,8 +808,20 @@ export class UserEntityService implements OnModuleInit {
let pinNotes: Map<MiUser['id'], MiUserNotePining[]> = new Map();
if (options?.schema !== 'UserLite') {
- profilesMap = await this.userProfilesRepository.findBy({ userId: In(_userIds) })
- .then(profiles => new Map(profiles.map(p => [p.userId, p])));
+ const _profiles: MiUserProfile[] = [];
+ const _profilesToFetch: string[] = [];
+ for (const user of _users) {
+ if (user.userProfile) {
+ _profiles.push(user.userProfile);
+ } else {
+ _profilesToFetch.push(user.id);
+ }
+ }
+ if (_profilesToFetch.length > 0) {
+ const fetched = await this.userProfilesRepository.findBy({ userId: In(_profilesToFetch) });
+ _profiles.push(...fetched);
+ }
+ profilesMap = new Map(_profiles.map(p => [p.userId, p]));
const meId = me ? me.id : null;
if (meId) {