mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 09:53:08 +02:00
24 lines
824 B
TypeScript
24 lines
824 B
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import type { User } from '@/models/entities/User.js';
|
|
import type { UserKeypairsRepository } from '@/models/index.js';
|
|
import { Cache } from '@/misc/cache.js';
|
|
import type { UserKeypair } from '@/models/entities/UserKeypair.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { bindThis } from '@/decorators.js';
|
|
|
|
@Injectable()
|
|
export class UserKeypairStoreService {
|
|
private cache: Cache<UserKeypair>;
|
|
|
|
constructor(
|
|
@Inject(DI.userKeypairsRepository)
|
|
private userKeypairsRepository: UserKeypairsRepository,
|
|
) {
|
|
this.cache = new Cache<UserKeypair>(Infinity);
|
|
}
|
|
|
|
@bindThis
|
|
public async getUserKeypair(userId: User['id']): Promise<UserKeypair> {
|
|
return await this.cache.fetch(userId, () => this.userKeypairsRepository.findOneByOrFail({ userId: userId }));
|
|
}
|
|
}
|