Use Redis event

This commit is contained in:
mei23 2024-02-14 23:54:51 +09:00
parent b824615a6b
commit 4e6cf78e29
No known key found for this signature in database
GPG key ID: DD8628500D3E4B23
2 changed files with 21 additions and 11 deletions

View file

@ -161,7 +161,15 @@ export class CacheService implements OnApplicationShutdown {
switch (type) {
case 'userChangeSuspendedState':
case 'remoteUserUpdated': {
const user = await this.usersRepository.findOneByOrFail({ id: body.id });
const user = await this.usersRepository.findOneBy({ id: body.id });
if (user == null) {
this.userByIdCache.delete(body.id);
for (const [k, v] of this.uriPersonCache.cache.entries()) {
if (v.value === body.id) {
this.uriPersonCache.delete(k);
}
}
} else {
this.userByIdCache.set(user.id, user);
for (const [k, v] of this.uriPersonCache.cache.entries()) {
if (v.value === user.id) {
@ -172,6 +180,7 @@ export class CacheService implements OnApplicationShutdown {
this.localUserByNativeTokenCache.set(user.token!, user);
this.localUserByIdCache.set(user.id, user);
}
}
break;
}
case 'userTokenRegenerated': {

View file

@ -36,6 +36,7 @@ import { ApAudienceService } from './ApAudienceService.js';
import { ApPersonService } from './models/ApPersonService.js';
import { ApQuestionService } from './models/ApQuestionService.js';
import { CacheService } from '@/core/CacheService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
import type { Resolver } from './ApResolverService.js';
import type { IAccept, IAdd, IAnnounce, IBlock, ICreate, IDelete, IFlag, IFollow, ILike, IObject, IReject, IRemove, IUndo, IUpdate, IMove } from './type.js';
@ -84,6 +85,7 @@ export class ApInboxService {
private apQuestionService: ApQuestionService,
private queueService: QueueService,
private cacheService: CacheService,
private globalEventService: GlobalEventService,
) {
this.logger = this.apLoggerService.logger;
}
@ -481,8 +483,7 @@ export class ApInboxService {
isDeleted: true,
});
this.cacheService.uriPersonCache.delete(actor.uri);
this.cacheService.userByIdCache.delete(actor.id);
this.globalEventService.publishInternalEvent('remoteUserUpdated', { id: actor.id });
return `ok: queued ${job.name} ${job.id}`;
}