refactor
This commit is contained in:
		
							parent
							
								
									bedb98185e
								
							
						
					
					
						commit
						e00003edff
					
				
					 2 changed files with 7 additions and 2 deletions
				
			
		|  | @ -2,7 +2,7 @@ import { Inject, Injectable } from '@nestjs/common'; | |||
| import Redis from 'ioredis'; | ||||
| import type { UsersRepository } from '@/models/index.js'; | ||||
| import { Cache } from '@/misc/cache.js'; | ||||
| import type { CacheableLocalUser, CacheableUser, ILocalUser } from '@/models/entities/User.js'; | ||||
| import type { CacheableLocalUser, CacheableUser, ILocalUser, User } from '@/models/entities/User.js'; | ||||
| import { DI } from '@/di-symbols.js'; | ||||
| import { UserEntityService } from '@/core/entities/UserEntityService.js'; | ||||
| import { bindThis } from '@/decorators.js'; | ||||
|  | @ -68,6 +68,11 @@ export class UserCacheService implements OnApplicationShutdown { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@bindThis | ||||
| 	public findById(userId: User['id']) { | ||||
| 		return this.userByIdCache.fetch(userId, () => this.usersRepository.findOneByOrFail({ id: userId })); | ||||
| 	} | ||||
| 
 | ||||
| 	@bindThis | ||||
| 	public onApplicationShutdown(signal?: string | undefined) { | ||||
| 		this.redisSubscriber.off('message', this.onMessage); | ||||
|  |  | |||
|  | @ -159,7 +159,7 @@ export class ApDbResolverService { | |||
| 		if (key == null) return null; | ||||
| 
 | ||||
| 		return { | ||||
| 			user: await this.userCacheService.userByIdCache.fetch(key.userId, () => this.usersRepository.findOneByOrFail({ id: key.userId })) as CacheableRemoteUser, | ||||
| 			user: await this.userCacheService.findById(key.userId) as CacheableRemoteUser, | ||||
| 			key, | ||||
| 		}; | ||||
| 	} | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue