summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-06-06 02:15:59 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-06-09 11:02:36 -0400
commit68b84b28dd23cd1afea286946c1ada7efc25fed0 (patch)
tree8519fb3e7ffd0be81d6fbdaa5dfd3af8c495e4ab /packages/backend/src
parentupdate quantum caches when a user is deleted (diff)
downloadsharkey-68b84b28dd23cd1afea286946c1ada7efc25fed0.tar.gz
sharkey-68b84b28dd23cd1afea286946c1ada7efc25fed0.tar.bz2
sharkey-68b84b28dd23cd1afea286946c1ada7efc25fed0.zip
implement CacheService.getUsers and CacheService.getUserProfiles
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/core/CacheService.ts56
1 files changed, 56 insertions, 0 deletions
diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts
index 1fba4f32d0..ae24a9721f 100644
--- a/packages/backend/src/core/CacheService.ts
+++ b/packages/backend/src/core/CacheService.ts
@@ -411,6 +411,62 @@ export class CacheService implements OnApplicationShutdown {
return blockers;
}
+ public async getUserProfiles(userIds: Iterable<string>): Promise<Map<string, MiUserProfile>> {
+ const profiles = new Map<string, MiUserProfile>;
+
+ const toFetch: string[] = [];
+ for (const userId of userIds) {
+ const fromCache = this.userProfileCache.get(userId);
+ if (fromCache) {
+ profiles.set(userId, fromCache);
+ } else {
+ toFetch.push(userId);
+ }
+ }
+
+ if (toFetch.length > 0) {
+ const fetched = await this.userProfilesRepository.findBy({
+ userId: In(toFetch),
+ });
+
+ for (const profile of fetched) {
+ profiles.set(profile.userId, profile);
+ }
+
+ const toCache = new Map(fetched.map(p => [p.userId, p]));
+ this.userProfileCache.addMany(toCache);
+ }
+
+ return profiles;
+ }
+
+ public async getUsers(userIds: Iterable<string>): Promise<Map<string, MiUser>> {
+ const users = new Map<string, MiUser>;
+
+ const toFetch: string[] = [];
+ for (const userId of userIds) {
+ const fromCache = this.userByIdCache.get(userId);
+ if (fromCache) {
+ users.set(userId, fromCache);
+ } else {
+ toFetch.push(userId);
+ }
+ }
+
+ if (toFetch.length > 0) {
+ const fetched = await this.usersRepository.findBy({
+ id: In(toFetch),
+ });
+
+ for (const user of fetched) {
+ users.set(user.id, user);
+ this.userByIdCache.set(user.id, user);
+ }
+ }
+
+ return users;
+ }
+
@bindThis
public dispose(): void {
this.internalEventService.off('userChangeSuspendedState', this.onUserEvent);