Skip to content

Commit

Permalink
リモートユーザーが復活してもキャッシュにより該当ユーザーのActivityが受け入れられないのを修正 Fix misskey-dev#13273
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Feb 12, 2024
1 parent b95e250 commit 1150a1a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/backend/src/core/CacheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class CacheService implements OnApplicationShutdown {
this.uriPersonCache = new MemoryKVCache<MiUser | null, string | null>(Infinity, {
toMapConverter: user => {
if (user === null) return null;
if (user.isDeleted) return null;

userByIdCache.set(user.id, user);
return user.id;
Expand Down
11 changes: 8 additions & 3 deletions packages/backend/src/core/activitypub/ApDbResolverService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ export class ApDbResolverService implements OnApplicationShutdown {

return await this.cacheService.userByIdCache.fetchMaybe(
parsed.id,
() => this.usersRepository.findOneBy({ id: parsed.id }).then(x => x ?? undefined),
() => this.usersRepository.findOneBy({ id: parsed.id, isDeleted: false }).then(x => x ?? undefined),
) as MiLocalUser | undefined ?? null;
} else {
return await this.cacheService.uriPersonCache.fetch(
parsed.uri,
() => this.usersRepository.findOneBy({ uri: parsed.uri }),
() => this.usersRepository.findOneBy({ uri: parsed.uri, isDeleted: false }),
) as MiRemoteUser | null;
}
}
Expand All @@ -136,8 +136,12 @@ export class ApDbResolverService implements OnApplicationShutdown {

if (key == null) return null;

const user = await this.cacheService.findUserById(key.userId).catch(() => null) as MiRemoteUser | null;
if (user == null) return null;
if (user.isDeleted) return null;

return {
user: await this.cacheService.findUserById(key.userId) as MiRemoteUser,
user,
key,
};
}
Expand All @@ -151,6 +155,7 @@ export class ApDbResolverService implements OnApplicationShutdown {
key: MiUserPublickey | null;
} | null> {
const user = await this.apPersonService.resolvePerson(uri) as MiRemoteUser;
if (user.isDeleted) return null;

const key = await this.publicKeyByUserIdCache.fetch(
user.id,
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/core/activitypub/ApInboxService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ApResolverService } from './ApResolverService.js';
import { ApAudienceService } from './ApAudienceService.js';
import { ApPersonService } from './models/ApPersonService.js';
import { ApQuestionService } from './models/ApQuestionService.js';
import { CacheService } from '@/core/CacheService.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';

Expand Down Expand Up @@ -82,6 +83,7 @@ export class ApInboxService {
private apPersonService: ApPersonService,
private apQuestionService: ApQuestionService,
private queueService: QueueService,
private cacheService: CacheService,
) {
this.logger = this.apLoggerService.logger;
}
Expand Down Expand Up @@ -479,6 +481,9 @@ export class ApInboxService {
isDeleted: true,
});

this.cacheService.uriPersonCache.delete(actor.uri);
this.cacheService.userByIdCache.delete(actor.id);

return `ok: queued ${job.name} ${job.id}`;
}

Expand Down

0 comments on commit 1150a1a

Please sign in to comment.