fix cherry-pick errors

This commit is contained in:
Hazelnoot 2025-11-07 00:22:32 -05:00
parent 332805b051
commit bc80fd7c49
4 changed files with 37 additions and 37 deletions

View file

@ -107,15 +107,25 @@ export class ApDbResolverService implements OnApplicationShutdown {
if (parsed.local) {
if (parsed.type !== 'users') return null;
return await this.cacheService.userByIdCache.fetchMaybe(
parsed.id,
() => this.usersRepository.findOneBy({ id: parsed.id, isDeleted: false }).then(x => x ?? undefined),
) as MiLocalUser | undefined ?? null;
const u = await this.cacheService.findOptionalUserById(parsed.id);
if (u == null || u.isDeleted) {
return null;
}
return u as MiLocalUser | MiRemoteUser;
} else {
return await this.cacheService.uriPersonCache.fetch(
parsed.uri,
() => this.usersRepository.findOneBy({ uri: parsed.uri, isDeleted: false }),
) as MiRemoteUser | null;
const uid = await this.apPersonService.uriPersonCache.fetchMaybe(parsed.uri);
if (uid == null) {
return null;
}
const u = await this.cacheService.findOptionalUserById(uid);
if (u == null || u.isDeleted) {
return null;
}
return u as MiLocalUser | MiRemoteUser;
}
}

View file

@ -277,38 +277,28 @@ export class ApPersonService implements OnModuleInit {
* Misskeyに対象のPersonが登録されていればそれを返しnullを返します
*/
@bindThis
public async fetchPerson(uri: string, opts?: { withDeleted?: boolean, withSuspended?: boolean }): Promise<MiLocalUser | MiRemoteUser | null> {
const _opts = {
withDeleted: opts?.withDeleted ?? false,
withSuspended: opts?.withSuspended ?? true,
};
public async fetchPerson(uri: string): Promise<MiLocalUser | MiRemoteUser | null> {
const cached = await this.uriPersonCache.fetchMaybe(uri);
if (cached) return await this.cacheService.findOptionalUserById(cached) as MiRemoteUser | MiLocalUser | undefined ?? null;
let userId;
// Resolve URI -> User ID
const parsed = this.utilityService.parseUri(uri);
if (parsed.local) {
userId = parsed.type === 'users' ? parsed.id : null;
} else {
userId = await this.uriPersonCache.fetch(uri).catch(() => null);
// URIがこのサーバーを指しているならデータベースからフェッチ
if (uri.startsWith(`${this.config.url}/`)) {
const id = uri.split('/').pop();
const u = await this.usersRepository.findOneBy({ id }) as MiLocalUser | null;
if (u) await this.uriPersonCache.set(uri, u.id);
return u;
}
// No match
if (!userId) {
return null;
}
//#region このサーバーに既に登録されていたらそれを返す
const exist = await this.usersRepository.findOneBy({ uri }) as MiLocalUser | MiRemoteUser | null;
const user = await this.cacheService.findUserById(userId)
.catch(() => null) as MiLocalUser | MiRemoteUser | null;
if (user?.isDeleted && !_opts.withDeleted) {
return null;
}
if (user?.isSuspended && !_opts.withSuspended) {
return null;
if (exist) {
await this.uriPersonCache.set(uri, exist.id);
return exist;
}
//#endregion
return user;
return null;
}
private async resolveAvatarAndBanner(user: MiRemoteUser, icon: any, image: any, bgimg: any): Promise<Partial<Pick<MiRemoteUser, 'avatarId' | 'bannerId' | 'backgroundId' | 'avatarUrl' | 'bannerUrl' | 'backgroundUrl' | 'avatarBlurhash' | 'bannerBlurhash' | 'backgroundBlurhash'>>> {
@ -845,7 +835,7 @@ export class ApPersonService implements OnModuleInit {
}
//#region このサーバーに既に登録されていたらそれを返す
const exist = await this.fetchPerson(uri, { withDeleted: true });
const exist = await this.fetchPerson(uri);
if (exist) return exist;
//#endregion

View file

@ -116,7 +116,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const tokens = await query.getMany();
const users = await this.cacheService.getUsers(tokens.flatMap(token => token.granteeIds));
const users = await this.cacheService.findUsersById(tokens.flatMap(token => token.granteeIds));
const packedUsers = await this.userEntityService.packMany(Array.from(users.values()), me);
const packedUserMap = new Map(packedUsers.map(u => [u.id, u]));

View file

@ -84,7 +84,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
super(meta, paramDef, async (ps, me) => {
// Validate grantees
if (ps.grantees && ps.grantees.length > 0) {
const grantees = await this.cacheService.getUsers(ps.grantees);
const grantees = await this.cacheService.findUsersById(ps.grantees);
if (grantees.size !== ps.grantees.length) {
throw new ApiError(meta.errors.noSuchUser);