normalize cache constructors and detect duplicate cache names

This commit is contained in:
Hazelnoot 2025-11-02 11:58:28 -05:00
parent 151550602c
commit 8271dc199e
18 changed files with 95 additions and 61 deletions

View file

@ -36,7 +36,7 @@ export class AvatarDecorationService implements OnApplicationShutdown {
cacheManagementService: CacheManagementService,
) {
this.cache = cacheManagementService.createMemorySingleCache<MiAvatarDecoration[]>(1000 * 60 * 30); // 30s
this.cache = cacheManagementService.createMemorySingleCache<MiAvatarDecoration[]>('avatarDecorations', 1000 * 60 * 30); // 30s
this.internalEventService.on('avatarDecorationCreated', this.onAvatarEvent);
this.internalEventService.on('avatarDecorationUpdated', this.onAvatarEvent);

View file

@ -106,10 +106,10 @@ export class CacheService implements OnApplicationShutdown {
) {
//this.onMessage = this.onMessage.bind(this);
this.userByIdCache = this.cacheManagementService.createMemoryKVCache<MiUser>(1000 * 60 * 5); // 5m
this.localUserByNativeTokenCache = this.cacheManagementService.createMemoryKVCache<MiLocalUser | null>(1000 * 60 * 5); // 5m
this.localUserByIdCache = this.cacheManagementService.createMemoryKVCache<MiLocalUser>(1000 * 60 * 5); // 5m
this.uriPersonCache = this.cacheManagementService.createMemoryKVCache<MiUser | null>(1000 * 60 * 5); // 5m
this.userByIdCache = this.cacheManagementService.createMemoryKVCache<MiUser>('userById', 1000 * 60 * 5); // 5m
this.localUserByNativeTokenCache = this.cacheManagementService.createMemoryKVCache<MiLocalUser | null>('localUserByNativeToken', 1000 * 60 * 5); // 5m
this.localUserByIdCache = this.cacheManagementService.createMemoryKVCache<MiLocalUser>('localUserById', 1000 * 60 * 5); // 5m
this.uriPersonCache = this.cacheManagementService.createMemoryKVCache<MiUser | null>('uriPerson', 1000 * 60 * 5); // 5m
this.userProfileCache = this.cacheManagementService.createQuantumKVCache('userProfile', {
lifetime: 1000 * 60 * 30, // 30m
@ -345,7 +345,7 @@ export class CacheService implements OnApplicationShutdown {
},
});
this.userFollowStatsCache = this.cacheManagementService.createMemoryKVCache<FollowStats>(1000 * 60 * 10); // 10 minutes
this.userFollowStatsCache = this.cacheManagementService.createMemoryKVCache<FollowStats>('followStats', 1000 * 60 * 10); // 10 minutes
this.userFollowingChannelsCache = this.cacheManagementService.createQuantumKVCache<Set<string>>('userFollowingChannels', {
lifetime: 1000 * 60 * 30, // 30m

View file

@ -56,10 +56,10 @@ export class InstanceStatsService {
cacheManagementService: CacheManagementService,
) {
this.localPostsCache = cacheManagementService.createMemorySingleCache<number>(1000 * 60 * 60); // 1h
this.localUsersCache = cacheManagementService.createMemorySingleCache<number>(1000 * 60 * 60); // 1h
this.activeMonthCache = cacheManagementService.createMemorySingleCache<number>(1000 * 60 * 60 * 24); // 1d
this.activeSixMonthsCache = cacheManagementService.createMemorySingleCache<number>(1000 * 60 * 60 * 24 * 7); // 1w
this.localPostsCache = cacheManagementService.createMemorySingleCache<number>('localPosts', 1000 * 60 * 60); // 1h
this.localUsersCache = cacheManagementService.createMemorySingleCache<number>('localUsers', 1000 * 60 * 60); // 1h
this.activeMonthCache = cacheManagementService.createMemorySingleCache<number>('activeMonth', 1000 * 60 * 60 * 24); // 1d
this.activeSixMonthsCache = cacheManagementService.createMemorySingleCache<number>('activeSixMonths', 1000 * 60 * 60 * 24 * 7); // 1w
}
@bindThis

View file

@ -32,7 +32,7 @@ export class RelayService {
cacheManagementService: CacheManagementService,
) {
this.relaysCache = cacheManagementService.createMemorySingleCache<MiRelay[]>(1000 * 60 * 10); // 10m
this.relaysCache = cacheManagementService.createMemorySingleCache<MiRelay[]>('relay', 1000 * 60 * 10); // 10m
}
@bindThis

View file

@ -162,8 +162,8 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
cacheManagementService: CacheManagementService,
) {
this.rolesCache = cacheManagementService.createMemorySingleCache<MiRole[]>(1000 * 60 * 60); // 1h
this.roleAssignmentByUserIdCache = cacheManagementService.createMemoryKVCache<MiRoleAssignment[]>(1000 * 60 * 5); // 5m
this.rolesCache = cacheManagementService.createMemorySingleCache<MiRole[]>('roles', 1000 * 60 * 60); // 1h
this.roleAssignmentByUserIdCache = cacheManagementService.createMemoryKVCache<MiRoleAssignment[]>('roleAssignment', 1000 * 60 * 5); // 5m
// TODO additional cache for final calculation?
this.redisForSub.on('message', this.onMessage);

View file

@ -56,7 +56,7 @@ export class SystemAccountService implements OnApplicationShutdown {
cacheManagementService: CacheManagementService,
) {
this.cache = cacheManagementService.createMemoryKVCache<string>(1000 * 60 * 10); // 10m
this.cache = cacheManagementService.createMemoryKVCache<string>('systemAccount', 1000 * 60 * 10); // 10m
this.redisForSub.on('message', this.onMessage);
}

View file

@ -69,7 +69,7 @@ export class SystemWebhookService implements OnApplicationShutdown {
cacheManagementService: CacheManagementService,
) {
this.activeSystemWebhooks = cacheManagementService.createMemorySingleCache<MiSystemWebhook[]>(1000 * 60 * 60 * 12); // 12h
this.activeSystemWebhooks = cacheManagementService.createMemorySingleCache<MiSystemWebhook[]>('systemWebhooks', 1000 * 60 * 60 * 12); // 12h
this.internalEventService.on('systemWebhookCreated', this.onWebhookEvent);
this.internalEventService.on('systemWebhookUpdated', this.onWebhookEvent);

View file

@ -41,7 +41,7 @@ export class UserWebhookService implements OnApplicationShutdown {
cacheManagementService: CacheManagementService,
) {
this.activeWebhooks = cacheManagementService.createMemorySingleCache<MiWebhook[]>(1000 * 60 * 60 * 12); // 12h
this.activeWebhooks = cacheManagementService.createMemorySingleCache<MiWebhook[]>('userWebhooks', 1000 * 60 * 60 * 12); // 12h
this.internalEventService.on('webhookCreated', this.onWebhookEvent);
this.internalEventService.on('webhookUpdated', this.onWebhookEvent);