enhance(backend): improve cache
This commit is contained in:
parent
7f3afac0a2
commit
ecaf152b4a
21 changed files with 184 additions and 89 deletions
|
@ -3,7 +3,7 @@ import { IsNull } from 'typeorm';
|
|||
import type { LocalUser, User } from '@/models/entities/User.js';
|
||||
import type { RelaysRepository, UsersRepository } from '@/models/index.js';
|
||||
import { IdService } from '@/core/IdService.js';
|
||||
import { MemoryKVCache } from '@/misc/cache.js';
|
||||
import { MemoryCache } from '@/misc/cache.js';
|
||||
import type { Relay } from '@/models/entities/Relay.js';
|
||||
import { QueueService } from '@/core/QueueService.js';
|
||||
import { CreateSystemUserService } from '@/core/CreateSystemUserService.js';
|
||||
|
@ -16,7 +16,7 @@ const ACTOR_USERNAME = 'relay.actor' as const;
|
|||
|
||||
@Injectable()
|
||||
export class RelayService {
|
||||
private relaysCache: MemoryKVCache<Relay[]>;
|
||||
private relaysCache: MemoryCache<Relay[]>;
|
||||
|
||||
constructor(
|
||||
@Inject(DI.usersRepository)
|
||||
|
@ -30,7 +30,7 @@ export class RelayService {
|
|||
private createSystemUserService: CreateSystemUserService,
|
||||
private apRendererService: ApRendererService,
|
||||
) {
|
||||
this.relaysCache = new MemoryKVCache<Relay[]>(1000 * 60 * 10);
|
||||
this.relaysCache = new MemoryCache<Relay[]>(1000 * 60 * 10);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
|
@ -109,7 +109,7 @@ export class RelayService {
|
|||
public async deliverToRelays(user: { id: User['id']; host: null; }, activity: any): Promise<void> {
|
||||
if (activity == null) return;
|
||||
|
||||
const relays = await this.relaysCache.fetch(null, () => this.relaysRepository.findBy({
|
||||
const relays = await this.relaysCache.fetch(() => this.relaysRepository.findBy({
|
||||
status: 'accepted',
|
||||
}));
|
||||
if (relays.length === 0) return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue