2022-09-17 13:27:08 -05:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import type { User } from '@/models/entities/User.js';
|
2022-09-20 15:33:11 -05:00
|
|
|
import type { UserKeypairsRepository } from '@/models/index.js';
|
2022-09-17 13:27:08 -05:00
|
|
|
import { Cache } from '@/misc/cache.js';
|
|
|
|
import type { UserKeypair } from '@/models/entities/UserKeypair.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class UserKeypairStoreService {
|
2022-09-18 13:11:50 -05:00
|
|
|
private cache: Cache<UserKeypair>;
|
2022-09-17 13:27:08 -05:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.userKeypairsRepository)
|
|
|
|
private userKeypairsRepository: UserKeypairsRepository,
|
|
|
|
) {
|
2022-09-18 13:11:50 -05:00
|
|
|
this.cache = new Cache<UserKeypair>(Infinity);
|
2022-09-17 13:27:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public async getUserKeypair(userId: User['id']): Promise<UserKeypair> {
|
2022-09-18 13:11:50 -05:00
|
|
|
return await this.cache.fetch(userId, () => this.userKeypairsRepository.findOneByOrFail({ userId: userId }));
|
2022-09-17 13:27:08 -05:00
|
|
|
}
|
|
|
|
}
|