refactor: introduce bindThis decorator to bind this automaticaly
This commit is contained in:
parent
e73581f715
commit
bbb49457f9
199 changed files with 969 additions and 96 deletions
|
@ -6,6 +6,7 @@ import type { CacheableLocalUser, CacheableUser, ILocalUser } from '@/models/ent
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class UserCacheService implements OnApplicationShutdown {
|
||||
|
@ -23,7 +24,7 @@ export class UserCacheService implements OnApplicationShutdown {
|
|||
|
||||
private userEntityService: UserEntityService,
|
||||
) {
|
||||
this.onMessage = this.onMessage.bind(this);
|
||||
//this.onMessage = this.onMessage.bind(this);
|
||||
|
||||
this.userByIdCache = new Cache<CacheableUser>(Infinity);
|
||||
this.localUserByNativeTokenCache = new Cache<CacheableLocalUser | null>(Infinity);
|
||||
|
@ -33,6 +34,7 @@ export class UserCacheService implements OnApplicationShutdown {
|
|||
this.redisSubscriber.on('message', this.onMessage);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async onMessage(_: string, data: string): Promise<void> {
|
||||
const obj = JSON.parse(data);
|
||||
|
||||
|
@ -68,6 +70,7 @@ export class UserCacheService implements OnApplicationShutdown {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public onApplicationShutdown(signal?: string | undefined) {
|
||||
this.redisSubscriber.off('message', this.onMessage);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue