summaryrefslogtreecommitdiff
path: root/packages/backend/src/core
diff options
context:
space:
mode:
authorHazel K <acomputerdog@gmail.com>2024-08-03 14:49:06 -0400
committerHazel K <acomputerdog@gmail.com>2024-08-03 14:49:06 -0400
commit672f1ea68476f5d325c2c996eb3020fd69e99aad (patch)
tree9bd31faf68aa1219f3f6b4cf19e37a7c9d1f0582 /packages/backend/src/core
parentimplement pull-through caching (diff)
downloadsharkey-672f1ea68476f5d325c2c996eb3020fd69e99aad.tar.gz
sharkey-672f1ea68476f5d325c2c996eb3020fd69e99aad.tar.bz2
sharkey-672f1ea68476f5d325c2c996eb3020fd69e99aad.zip
tune cache lifetimes
Diffstat (limited to 'packages/backend/src/core')
-rw-r--r--packages/backend/src/core/AvatarDecorationService.ts2
-rw-r--r--packages/backend/src/core/CustomEmojiService.ts14
-rw-r--r--packages/backend/src/core/RelayService.ts2
-rw-r--r--packages/backend/src/core/RoleService.ts6
-rw-r--r--packages/backend/src/core/UserKeypairService.ts2
5 files changed, 12 insertions, 14 deletions
diff --git a/packages/backend/src/core/AvatarDecorationService.ts b/packages/backend/src/core/AvatarDecorationService.ts
index 21e31d79a4..fa3f63677e 100644
--- a/packages/backend/src/core/AvatarDecorationService.ts
+++ b/packages/backend/src/core/AvatarDecorationService.ts
@@ -29,7 +29,7 @@ export class AvatarDecorationService implements OnApplicationShutdown {
private moderationLogService: ModerationLogService,
private globalEventService: GlobalEventService,
) {
- this.cache = new MemorySingleCache<MiAvatarDecoration[]>(1000 * 60 * 30);
+ this.cache = new MemorySingleCache<MiAvatarDecoration[]>(1000 * 60 * 30); // 30s
this.redisForSub.on('message', this.onMessage);
}
diff --git a/packages/backend/src/core/CustomEmojiService.ts b/packages/backend/src/core/CustomEmojiService.ts
index bfbc2b172d..098e94991c 100644
--- a/packages/backend/src/core/CustomEmojiService.ts
+++ b/packages/backend/src/core/CustomEmojiService.ts
@@ -26,7 +26,7 @@ const parseEmojiStrRegexp = /^([-\w]+)(?:@([\w.-]+))?$/;
@Injectable()
export class CustomEmojiService implements OnApplicationShutdown {
- private cache: MemoryKVCache<MiEmoji | null>;
+ private emojisCache: MemoryKVCache<MiEmoji | null>;
public localEmojisCache: RedisSingleCache<Map<string, MiEmoji>>;
constructor(
@@ -49,7 +49,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
private globalEventService: GlobalEventService,
private driveService: DriveService,
) {
- this.cache = new MemoryKVCache<MiEmoji | null>(1000 * 60 * 60 * 12);
+ this.emojisCache = new MemoryKVCache<MiEmoji | null>(1000 * 60 * 60 * 12); // 12h
this.localEmojisCache = new RedisSingleCache<Map<string, MiEmoji>>(this.redisClient, 'localEmojis', {
lifetime: 1000 * 60 * 30, // 30m
@@ -350,14 +350,14 @@ export class CustomEmojiService implements OnApplicationShutdown {
if (name == null) return null;
if (host == null) return null;
- const newHost = host === this.config.host ? null : host;
+ const newHost = host === this.config.host ? null : host;
const queryOrNull = async () => (await this.emojisRepository.findOneBy({
name,
host: newHost ?? IsNull(),
})) ?? null;
- const emoji = await this.cache.fetch(`${name} ${host}`, queryOrNull);
+ const emoji = await this.emojisCache.fetch(`${name} ${host}`, queryOrNull);
if (emoji == null) return null;
return emoji.publicUrl || emoji.originalUrl; // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ)
@@ -384,7 +384,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
*/
@bindThis
public async prefetchEmojis(emojis: { name: string; host: string | null; }[]): Promise<void> {
- const notCachedEmojis = emojis.filter(emoji => this.cache.get(`${emoji.name} ${emoji.host}`) == null);
+ const notCachedEmojis = emojis.filter(emoji => this.emojisCache.get(`${emoji.name} ${emoji.host}`) == null);
const emojisQuery: any[] = [];
const hosts = new Set(notCachedEmojis.map(e => e.host));
for (const host of hosts) {
@@ -399,7 +399,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
select: ['name', 'host', 'originalUrl', 'publicUrl'],
}) : [];
for (const emoji of _emojis) {
- this.cache.set(`${emoji.name} ${emoji.host}`, emoji);
+ this.emojisCache.set(`${emoji.name} ${emoji.host}`, emoji);
}
}
@@ -424,7 +424,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
@bindThis
public dispose(): void {
- this.cache.dispose();
+ this.emojisCache.dispose();
}
@bindThis
diff --git a/packages/backend/src/core/RelayService.ts b/packages/backend/src/core/RelayService.ts
index e9dc9b57af..9caeaf1714 100644
--- a/packages/backend/src/core/RelayService.ts
+++ b/packages/backend/src/core/RelayService.ts
@@ -35,7 +35,7 @@ export class RelayService {
private createSystemUserService: CreateSystemUserService,
private apRendererService: ApRendererService,
) {
- this.relaysCache = new MemorySingleCache<MiRelay[]>(1000 * 60 * 10);
+ this.relaysCache = new MemorySingleCache<MiRelay[]>(1000 * 60 * 10); // 10s
}
@bindThis
diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts
index f5a753afc7..f46aacaef4 100644
--- a/packages/backend/src/core/RoleService.ts
+++ b/packages/backend/src/core/RoleService.ts
@@ -129,10 +129,8 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
private moderationLogService: ModerationLogService,
private fanoutTimelineService: FanoutTimelineService,
) {
- //this.onMessage = this.onMessage.bind(this);
-
- this.rolesCache = new MemorySingleCache<MiRole[]>(1000 * 60 * 60 * 1);
- this.roleAssignmentByUserIdCache = new MemoryKVCache<MiRoleAssignment[]>(1000 * 60 * 60 * 1);
+ this.rolesCache = new MemorySingleCache<MiRole[]>(1000 * 60 * 60); // 1h
+ this.roleAssignmentByUserIdCache = new MemoryKVCache<MiRoleAssignment[]>(1000 * 60 * 5); // 1h
this.redisForSub.on('message', this.onMessage);
}
diff --git a/packages/backend/src/core/UserKeypairService.ts b/packages/backend/src/core/UserKeypairService.ts
index eb7a95da3e..92d61cd103 100644
--- a/packages/backend/src/core/UserKeypairService.ts
+++ b/packages/backend/src/core/UserKeypairService.ts
@@ -25,7 +25,7 @@ export class UserKeypairService implements OnApplicationShutdown {
) {
this.cache = new RedisKVCache<MiUserKeypair>(this.redisClient, 'userKeypair', {
lifetime: 1000 * 60 * 60 * 24, // 24h
- memoryCacheLifetime: 1000 * 60 * 60 * 12, // 12h
+ memoryCacheLifetime: 1000 * 60 * 60, // 1h
fetcher: (key) => this.userKeypairsRepository.findOneByOrFail({ userId: key }),
toRedisConverter: (value) => JSON.stringify(value),
fromRedisConverter: (value) => JSON.parse(value),