diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-06-12 15:42:39 +0000 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-06-12 15:42:39 +0000 |
| commit | 55551a5a8a3a218b9f56491f2dbe3f70e3ef3556 (patch) | |
| tree | 927f789e18162a91da0144356d040995864613ee /packages/backend/src/core/UserKeypairService.ts | |
| parent | merge: Enforce DM visibility in generateVisibilityQuery (!1108) (diff) | |
| parent | fix relations in MastodonDataService.ts (diff) | |
| download | sharkey-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/UserKeypairService.ts')
| -rw-r--r-- | packages/backend/src/core/UserKeypairService.ts | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/packages/backend/src/core/UserKeypairService.ts b/packages/backend/src/core/UserKeypairService.ts index 92d61cd103..d8a67d273b 100644 --- a/packages/backend/src/core/UserKeypairService.ts +++ b/packages/backend/src/core/UserKeypairService.ts @@ -7,14 +7,14 @@ import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common'; import * as Redis from 'ioredis'; import type { MiUser } from '@/models/User.js'; import type { UserKeypairsRepository } from '@/models/_.js'; -import { RedisKVCache } from '@/misc/cache.js'; +import { MemoryKVCache, RedisKVCache } from '@/misc/cache.js'; import type { MiUserKeypair } from '@/models/UserKeypair.js'; import { DI } from '@/di-symbols.js'; import { bindThis } from '@/decorators.js'; @Injectable() export class UserKeypairService implements OnApplicationShutdown { - private cache: RedisKVCache<MiUserKeypair>; + private cache: MemoryKVCache<MiUserKeypair>; constructor( @Inject(DI.redis) @@ -23,18 +23,12 @@ export class UserKeypairService implements OnApplicationShutdown { @Inject(DI.userKeypairsRepository) private userKeypairsRepository: UserKeypairsRepository, ) { - this.cache = new RedisKVCache<MiUserKeypair>(this.redisClient, 'userKeypair', { - lifetime: 1000 * 60 * 60 * 24, // 24h - memoryCacheLifetime: 1000 * 60 * 60, // 1h - fetcher: (key) => this.userKeypairsRepository.findOneByOrFail({ userId: key }), - toRedisConverter: (value) => JSON.stringify(value), - fromRedisConverter: (value) => JSON.parse(value), - }); + this.cache = new MemoryKVCache<MiUserKeypair>(1000 * 60 * 60 * 24); // 24h } @bindThis public async getUserKeypair(userId: MiUser['id']): Promise<MiUserKeypair> { - return await this.cache.fetch(userId); + return await this.cache.fetch(userId, () => this.userKeypairsRepository.findOneByOrFail({ userId })); } @bindThis |