From 55c80db66d32e0e94a4ceb8bcfbb2ae761e5986a Mon Sep 17 00:00:00 2001 From: mattyatea Date: Sat, 11 May 2024 01:12:26 +0900 Subject: [PATCH] update --- packages/backend/src/core/CacheService.ts | 13 ------------- .../src/core/FanoutTimelineEndpointService.ts | 6 ++++-- packages/backend/src/core/NotificationService.ts | 7 +++++-- .../src/core/entities/NotificationEntityService.ts | 13 ++++++++++--- .../backend/src/server/api/endpoints/i/update.ts | 2 -- .../backend/src/server/api/stream/Connection.ts | 9 ++++++--- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts index d008e7ec52..28f14504ae 100644 --- a/packages/backend/src/core/CacheService.ts +++ b/packages/backend/src/core/CacheService.ts @@ -20,7 +20,6 @@ export class CacheService implements OnApplicationShutdown { public localUserByNativeTokenCache: MemoryKVCache; public localUserByIdCache: MemoryKVCache; public uriPersonCache: MemoryKVCache; - public userProfileCache: RedisKVCache; public userMutingsCache: RedisKVCache>; public userBlockingCache: RedisKVCache>; public userBlockedCache: RedisKVCache>; // NOTE: 「被」Blockキャッシュ @@ -37,9 +36,6 @@ export class CacheService implements OnApplicationShutdown { @Inject(DI.usersRepository) private usersRepository: UsersRepository, - @Inject(DI.userProfilesRepository) - private userProfilesRepository: UserProfilesRepository, - @Inject(DI.mutingsRepository) private mutingsRepository: MutingsRepository, @@ -61,14 +57,6 @@ export class CacheService implements OnApplicationShutdown { this.localUserByIdCache = new MemoryKVCache(Infinity); this.uriPersonCache = new MemoryKVCache(Infinity); - this.userProfileCache = new RedisKVCache(this.redisClient, 'userProfile', { - lifetime: 1000 * 60 * 30, // 30m - memoryCacheLifetime: 1000 * 60, // 1m - fetcher: (key) => this.userProfilesRepository.findOneByOrFail({ userId: key }), - toRedisConverter: (value) => JSON.stringify(value), - fromRedisConverter: (value) => JSON.parse(value), // TODO: date型の考慮 - }); - this.userMutingsCache = new RedisKVCache>(this.redisClient, 'userMutings', { lifetime: 1000 * 60 * 30, // 30m memoryCacheLifetime: 1000 * 60, // 1m @@ -186,7 +174,6 @@ export class CacheService implements OnApplicationShutdown { this.localUserByNativeTokenCache.dispose(); this.localUserByIdCache.dispose(); this.uriPersonCache.dispose(); - this.userProfileCache.dispose(); this.userMutingsCache.dispose(); this.userBlockingCache.dispose(); this.userBlockedCache.dispose(); diff --git a/packages/backend/src/core/FanoutTimelineEndpointService.ts b/packages/backend/src/core/FanoutTimelineEndpointService.ts index 884723ff81..fa52c7a2b8 100644 --- a/packages/backend/src/core/FanoutTimelineEndpointService.ts +++ b/packages/backend/src/core/FanoutTimelineEndpointService.ts @@ -9,7 +9,7 @@ import { bindThis } from '@/decorators.js'; import type { MiUser } from '@/models/User.js'; import type { MiNote } from '@/models/Note.js'; import { Packed } from '@/misc/json-schema.js'; -import type { NotesRepository } from '@/models/_.js'; +import type { NotesRepository, UserProfilesRepository } from '@/models/_.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { FanoutTimelineName, FanoutTimelineService } from '@/core/FanoutTimelineService.js'; import { isUserRelated } from '@/misc/is-user-related.js'; @@ -41,6 +41,8 @@ export class FanoutTimelineEndpointService { constructor( @Inject(DI.notesRepository) private notesRepository: NotesRepository, + @Inject(DI.userProfilesRepository) + private userProfilesRepository: UserProfilesRepository, private noteEntityService: NoteEntityService, private cacheService: CacheService, @@ -109,7 +111,7 @@ export class FanoutTimelineEndpointService { this.cacheService.userMutingsCache.fetch(ps.me.id), this.cacheService.renoteMutingsCache.fetch(ps.me.id), this.cacheService.userBlockedCache.fetch(ps.me.id), - this.cacheService.userProfileCache.fetch(me.id).then(p => new Set(p.mutedInstances)), + (await this.userProfilesRepository.findOneByOrFail({ userId: me.id }).then(p => new Set(p.mutedInstances))), ]); const parentFilter = filter; diff --git a/packages/backend/src/core/NotificationService.ts b/packages/backend/src/core/NotificationService.ts index 68ad92f396..faccc76ab9 100644 --- a/packages/backend/src/core/NotificationService.ts +++ b/packages/backend/src/core/NotificationService.ts @@ -8,7 +8,7 @@ import * as Redis from 'ioredis'; import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common'; import { In } from 'typeorm'; import { DI } from '@/di-symbols.js'; -import type { UsersRepository } from '@/models/_.js'; +import type { UserProfilesRepository, UsersRepository } from '@/models/_.js'; import type { MiUser } from '@/models/User.js'; import type { MiNotification } from '@/models/Notification.js'; import { bindThis } from '@/decorators.js'; @@ -36,6 +36,9 @@ export class NotificationService implements OnApplicationShutdown { @Inject(DI.usersRepository) private usersRepository: UsersRepository, + @Inject(DI.userProfilesRepository) + private userProfilesRepository: UserProfilesRepository, + private notificationEntityService: NotificationEntityService, private idService: IdService, private globalEventService: GlobalEventService, @@ -92,7 +95,7 @@ export class NotificationService implements OnApplicationShutdown { data: Omit, 'type' | 'id' | 'createdAt' | 'notifierId'>, notifierId?: MiUser['id'] | null, ): Promise { - const profile = await this.cacheService.userProfileCache.fetch(notifieeId); + const profile = await this.userProfilesRepository.findOneByOrFail({ userId: notifieeId }); // 古いMisskeyバージョンのキャッシュが残っている可能性がある // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition diff --git a/packages/backend/src/core/entities/NotificationEntityService.ts b/packages/backend/src/core/entities/NotificationEntityService.ts index 94d56c883b..96c097bfd0 100644 --- a/packages/backend/src/core/entities/NotificationEntityService.ts +++ b/packages/backend/src/core/entities/NotificationEntityService.ts @@ -7,7 +7,13 @@ import { Inject, Injectable } from '@nestjs/common'; import { ModuleRef } from '@nestjs/core'; import { In } from 'typeorm'; import { DI } from '@/di-symbols.js'; -import type { FollowRequestsRepository, NotesRepository, MiUser, UsersRepository } from '@/models/_.js'; +import type { + FollowRequestsRepository, + NotesRepository, + MiUser, + UsersRepository, + UserProfilesRepository, +} from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { MiGroupedNotification, MiNotification } from '@/models/Notification.js'; import type { MiNote } from '@/models/Note.js'; @@ -42,7 +48,8 @@ export class NotificationEntityService implements OnModuleInit { private followRequestsRepository: FollowRequestsRepository, private cacheService: CacheService, - + @Inject(DI.userProfilesRepository) + private userProfilesRepository: UserProfilesRepository, //private userEntityService: UserEntityService, //private noteEntityService: NoteEntityService, ) { @@ -302,7 +309,7 @@ export class NotificationEntityService implements OnModuleInit { userMutedInstances, ] = await Promise.all([ this.cacheService.userMutingsCache.fetch(meId), - this.cacheService.userProfileCache.fetch(meId).then(p => new Set(p.mutedInstances)), + await this.userProfilesRepository.findOneByOrFail({ userId: meId }).then(p => new Set(p.mutedInstances)), ]); const notifierIds = notifications.map(notification => 'notifierId' in notification ? notification.notifierId : null).filter(isNotNull); diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index ee51930036..1b2468cdcb 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -477,8 +477,6 @@ export default class extends Endpoint { // eslint- const updatedProfile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id }); - await this.cacheService.userProfileCache.set(user.id, updatedProfile); - // Publish meUpdated event this.globalEventService.publishMainStream(user.id, 'meUpdated', iObj); diff --git a/packages/backend/src/server/api/stream/Connection.ts b/packages/backend/src/server/api/stream/Connection.ts index 41c0feccc7..f6912ce869 100644 --- a/packages/backend/src/server/api/stream/Connection.ts +++ b/packages/backend/src/server/api/stream/Connection.ts @@ -4,6 +4,7 @@ */ import * as WebSocket from 'ws'; +import { Inject } from '@nestjs/common'; import type { MiUser } from '@/models/User.js'; import type { MiAccessToken } from '@/models/AccessToken.js'; import type { Packed } from '@/misc/json-schema.js'; @@ -11,9 +12,10 @@ import type { NoteReadService } from '@/core/NoteReadService.js'; import type { NotificationService } from '@/core/NotificationService.js'; import { bindThis } from '@/decorators.js'; import { CacheService } from '@/core/CacheService.js'; -import { MiFollowing, MiUserProfile } from '@/models/_.js'; +import { MiFollowing, MiUserProfile, type UserProfilesRepository } from '@/models/_.js'; import type { StreamEventEmitter, GlobalEvents } from '@/core/GlobalEventService.js'; import { ChannelFollowingService } from '@/core/ChannelFollowingService.js'; +import { DI } from '@/di-symbols.js'; import type { ChannelsService } from './ChannelsService.js'; import type { EventEmitter } from 'events'; import type Channel from './channel.js'; @@ -45,7 +47,8 @@ export default class Connection { private notificationService: NotificationService, private cacheService: CacheService, private channelFollowingService: ChannelFollowingService, - + @Inject(DI.userProfilesRepository) + private userProfilesRepository: UserProfilesRepository, user: MiUser | null | undefined, token: MiAccessToken | null | undefined, ) { @@ -57,7 +60,7 @@ export default class Connection { public async fetch() { if (this.user == null) return; const [userProfile, following, followingChannels, userIdsWhoMeMuting, userIdsWhoBlockingMe, userIdsWhoMeMutingRenotes] = await Promise.all([ - this.cacheService.userProfileCache.fetch(this.user.id), + await this.userProfilesRepository.findOneByOrFail({ userId: this.user.id }), this.cacheService.userFollowingsCache.fetch(this.user.id), this.channelFollowingService.userFollowingChannelsCache.fetch(this.user.id), this.cacheService.userMutingsCache.fetch(this.user.id),