diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-10-03 20:26:11 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-03 20:26:11 +0900 |
| commit | 6277a5545c746fac15ee6b4fe58de2e354ed7fda (patch) | |
| tree | 700b0d162795f03d644a15ba2375628d66f95d92 /packages/backend/src/core/CacheService.ts | |
| parent | Update about-misskey.vue (diff) | |
| download | sharkey-6277a5545c746fac15ee6b4fe58de2e354ed7fda.tar.gz sharkey-6277a5545c746fac15ee6b4fe58de2e354ed7fda.tar.bz2 sharkey-6277a5545c746fac15ee6b4fe58de2e354ed7fda.zip | |
feat: improve tl performance (#11946)
* wip
* wip
* wip
* wip
* wip
* wip
* Update NoteCreateService.ts
* wip
* wip
* wip
* wip
* Update NoteCreateService.ts
* wip
* Update NoteCreateService.ts
* wip
* Update user-notes.ts
* wip
* wip
* wip
* Update NoteCreateService.ts
* wip
* Update timeline.ts
* Update timeline.ts
* Update timeline.ts
* Update timeline.ts
* Update timeline.ts
* wip
* Update timelines.ts
* Update timelines.ts
* Update timelines.ts
* wip
* wip
* wip
* Update timelines.ts
* Update misskey-js.api.md
* Update timelines.ts
* Update timelines.ts
* wip
* wip
* wip
* Update timelines.ts
* wip
* Update timelines.ts
* wip
* test
* Update activitypub.ts
* refactor: UserListJoining -> UserListMembership
* Update NoteCreateService.ts
* wip
Diffstat (limited to 'packages/backend/src/core/CacheService.ts')
| -rw-r--r-- | packages/backend/src/core/CacheService.ts | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts index 561979c4bf..22c510cc37 100644 --- a/packages/backend/src/core/CacheService.ts +++ b/packages/backend/src/core/CacheService.ts @@ -5,7 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import * as Redis from 'ioredis'; -import type { BlockingsRepository, ChannelFollowingsRepository, FollowingsRepository, MutingsRepository, RenoteMutingsRepository, MiUserProfile, UserProfilesRepository, UsersRepository } from '@/models/_.js'; +import type { BlockingsRepository, ChannelFollowingsRepository, 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'; import { DI } from '@/di-symbols.js'; @@ -25,7 +25,7 @@ export class CacheService implements OnApplicationShutdown { public userBlockingCache: RedisKVCache<Set<string>>; public userBlockedCache: RedisKVCache<Set<string>>; // NOTE: 「被」Blockキャッシュ public renoteMutingsCache: RedisKVCache<Set<string>>; - public userFollowingsCache: RedisKVCache<Set<string>>; + public userFollowingsCache: RedisKVCache<Record<string, Pick<MiFollowing, 'withReplies'> | undefined>>; public userFollowingChannelsCache: RedisKVCache<Set<string>>; constructor( @@ -136,12 +136,18 @@ export class CacheService implements OnApplicationShutdown { fromRedisConverter: (value) => new Set(JSON.parse(value)), }); - this.userFollowingsCache = new RedisKVCache<Set<string>>(this.redisClient, 'userFollowings', { + this.userFollowingsCache = new RedisKVCache<Record<string, Pick<MiFollowing, 'withReplies'> | undefined>>(this.redisClient, 'userFollowings', { lifetime: 1000 * 60 * 30, // 30m memoryCacheLifetime: 1000 * 60, // 1m - fetcher: (key) => this.followingsRepository.find({ where: { followerId: key }, select: ['followeeId'] }).then(xs => new Set(xs.map(x => x.followeeId))), - toRedisConverter: (value) => JSON.stringify(Array.from(value)), - fromRedisConverter: (value) => new Set(JSON.parse(value)), + fetcher: (key) => this.followingsRepository.find({ where: { followerId: key }, select: ['followeeId', 'withReplies'] }).then(xs => { + const obj: Record<string, Pick<MiFollowing, 'withReplies'> | undefined> = {}; + for (const x of xs) { + obj[x.followeeId] = { withReplies: x.withReplies }; + } + return obj; + }), + toRedisConverter: (value) => JSON.stringify(value), + fromRedisConverter: (value) => JSON.parse(value), }); this.userFollowingChannelsCache = new RedisKVCache<Set<string>>(this.redisClient, 'userFollowingChannels', { @@ -188,6 +194,7 @@ export class CacheService implements OnApplicationShutdown { if (follower) follower.followingCount++; const followee = this.userByIdCache.get(body.followeeId); if (followee) followee.followersCount++; + this.userFollowingsCache.delete(body.followerId); break; } default: |