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,16 +161,25 @@ export class CacheService implements OnApplicationShutdown {
switch (type) { switch (type) {
case 'userChangeSuspendedState': case 'userChangeSuspendedState':
case 'remoteUserUpdated': { case 'remoteUserUpdated': {
const user = await this.usersRepository.findOneByOrFail({ id: body.id }); const user = await this.usersRepository.findOneBy({ id: body.id });
this.userByIdCache.set(user.id, user); if (user == null) {
for (const [k, v] of this.uriPersonCache.cache.entries()) { this.userByIdCache.delete(body.id);
if (v.value === user.id) { for (const [k, v] of this.uriPersonCache.cache.entries()) {
this.uriPersonCache.set(k, user); 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) {
this.uriPersonCache.set(k, user);
}
}
if (this.userEntityService.isLocalUser(user)) {
this.localUserByNativeTokenCache.set(user.token!, user);
this.localUserByIdCache.set(user.id, user);
} }
}
if (this.userEntityService.isLocalUser(user)) {
this.localUserByNativeTokenCache.set(user.token!, user);
this.localUserByIdCache.set(user.id, user);
} }
break; break;
} }

View File

@ -36,6 +36,7 @@ import { ApAudienceService } from './ApAudienceService.js';
import { ApPersonService } from './models/ApPersonService.js'; import { ApPersonService } from './models/ApPersonService.js';
import { ApQuestionService } from './models/ApQuestionService.js'; import { ApQuestionService } from './models/ApQuestionService.js';
import { CacheService } from '@/core/CacheService.js'; import { CacheService } from '@/core/CacheService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
import type { Resolver } from './ApResolverService.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'; 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 apQuestionService: ApQuestionService,
private queueService: QueueService, private queueService: QueueService,
private cacheService: CacheService, private cacheService: CacheService,
private globalEventService: GlobalEventService,
) { ) {
this.logger = this.apLoggerService.logger; this.logger = this.apLoggerService.logger;
} }
@ -481,8 +483,7 @@ export class ApInboxService {
isDeleted: true, isDeleted: true,
}); });
this.cacheService.uriPersonCache.delete(actor.uri); this.globalEventService.publishInternalEvent('remoteUserUpdated', { id: actor.id });
this.cacheService.userByIdCache.delete(actor.id);
return `ok: queued ${job.name} ${job.id}`; return `ok: queued ${job.name} ${job.id}`;
} }