summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/CacheService.ts
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-02-21 22:04:36 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-03-16 10:07:57 -0400
commita35c2f214b1b1054229f31569f6df4090a7375a5 (patch)
treea9e8c42026eeb6a4dcd0e582eefe506943afa0a5 /packages/backend/src/core/CacheService.ts
parentmerge: fetch linked notes manually, unless we have them in DB - fixes 1006 (!... (diff)
downloadsharkey-a35c2f214b1b1054229f31569f6df4090a7375a5.tar.gz
sharkey-a35c2f214b1b1054229f31569f6df4090a7375a5.tar.bz2
sharkey-a35c2f214b1b1054229f31569f6df4090a7375a5.zip
convert Authorized Fetch to a setting and add support for hybrid mode (essential metadata only)
Diffstat (limited to 'packages/backend/src/core/CacheService.ts')
-rw-r--r--packages/backend/src/core/CacheService.ts8
1 files changed, 8 insertions, 0 deletions
diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts
index 6725ebe75b..e9900373b4 100644
--- a/packages/backend/src/core/CacheService.ts
+++ b/packages/backend/src/core/CacheService.ts
@@ -5,6 +5,7 @@
import { Inject, Injectable } from '@nestjs/common';
import * as Redis from 'ioredis';
+import { IsNull } from 'typeorm';
import type { BlockingsRepository, FollowingsRepository, MutingsRepository, RenoteMutingsRepository, MiUserProfile, UserProfilesRepository, UsersRepository, MiFollowing } from '@/models/_.js';
import { MemoryKVCache, RedisKVCache } from '@/misc/cache.js';
import type { MiLocalUser, MiUser } from '@/models/User.js';
@@ -180,6 +181,13 @@ export class CacheService implements OnApplicationShutdown {
}
@bindThis
+ public async findLocalUserById(userId: MiUser['id']): Promise<MiLocalUser | null> {
+ return await this.localUserByIdCache.fetchMaybe(userId, async () => {
+ return await this.usersRepository.findOneBy({ id: userId, host: IsNull() }) as MiLocalUser | null ?? undefined;
+ }) ?? null;
+ }
+
+ @bindThis
public dispose(): void {
this.redisForSub.off('message', this.onMessage);
this.userByIdCache.dispose();