fix cherry-pick errors
This commit is contained in:
parent
332805b051
commit
bc80fd7c49
4 changed files with 37 additions and 37 deletions
|
|
@ -107,15 +107,25 @@ export class ApDbResolverService implements OnApplicationShutdown {
|
||||||
if (parsed.local) {
|
if (parsed.local) {
|
||||||
if (parsed.type !== 'users') return null;
|
if (parsed.type !== 'users') return null;
|
||||||
|
|
||||||
return await this.cacheService.userByIdCache.fetchMaybe(
|
const u = await this.cacheService.findOptionalUserById(parsed.id);
|
||||||
parsed.id,
|
|
||||||
() => this.usersRepository.findOneBy({ id: parsed.id, isDeleted: false }).then(x => x ?? undefined),
|
if (u == null || u.isDeleted) {
|
||||||
) as MiLocalUser | undefined ?? null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return u as MiLocalUser | MiRemoteUser;
|
||||||
} else {
|
} else {
|
||||||
return await this.cacheService.uriPersonCache.fetch(
|
const uid = await this.apPersonService.uriPersonCache.fetchMaybe(parsed.uri);
|
||||||
parsed.uri,
|
if (uid == null) {
|
||||||
() => this.usersRepository.findOneBy({ uri: parsed.uri, isDeleted: false }),
|
return null;
|
||||||
) as MiRemoteUser | null;
|
}
|
||||||
|
|
||||||
|
const u = await this.cacheService.findOptionalUserById(uid);
|
||||||
|
if (u == null || u.isDeleted) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return u as MiLocalUser | MiRemoteUser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -277,38 +277,28 @@ export class ApPersonService implements OnModuleInit {
|
||||||
* Misskeyに対象のPersonが登録されていればそれを返し、登録がなければnullを返します。
|
* Misskeyに対象のPersonが登録されていればそれを返し、登録がなければnullを返します。
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public async fetchPerson(uri: string, opts?: { withDeleted?: boolean, withSuspended?: boolean }): Promise<MiLocalUser | MiRemoteUser | null> {
|
public async fetchPerson(uri: string): Promise<MiLocalUser | MiRemoteUser | null> {
|
||||||
const _opts = {
|
const cached = await this.uriPersonCache.fetchMaybe(uri);
|
||||||
withDeleted: opts?.withDeleted ?? false,
|
if (cached) return await this.cacheService.findOptionalUserById(cached) as MiRemoteUser | MiLocalUser | undefined ?? null;
|
||||||
withSuspended: opts?.withSuspended ?? true,
|
|
||||||
};
|
|
||||||
|
|
||||||
let userId;
|
// URIがこのサーバーを指しているならデータベースからフェッチ
|
||||||
|
if (uri.startsWith(`${this.config.url}/`)) {
|
||||||
// Resolve URI -> User ID
|
const id = uri.split('/').pop();
|
||||||
const parsed = this.utilityService.parseUri(uri);
|
const u = await this.usersRepository.findOneBy({ id }) as MiLocalUser | null;
|
||||||
if (parsed.local) {
|
if (u) await this.uriPersonCache.set(uri, u.id);
|
||||||
userId = parsed.type === 'users' ? parsed.id : null;
|
return u;
|
||||||
} else {
|
|
||||||
userId = await this.uriPersonCache.fetch(uri).catch(() => null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No match
|
//#region このサーバーに既に登録されていたらそれを返す
|
||||||
if (!userId) {
|
const exist = await this.usersRepository.findOneBy({ uri }) as MiLocalUser | MiRemoteUser | null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = await this.cacheService.findUserById(userId)
|
if (exist) {
|
||||||
.catch(() => null) as MiLocalUser | MiRemoteUser | null;
|
await this.uriPersonCache.set(uri, exist.id);
|
||||||
|
return exist;
|
||||||
if (user?.isDeleted && !_opts.withDeleted) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (user?.isSuspended && !_opts.withSuspended) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
//#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'>>> {
|
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 このサーバーに既に登録されていたらそれを返す
|
//#region このサーバーに既に登録されていたらそれを返す
|
||||||
const exist = await this.fetchPerson(uri, { withDeleted: true });
|
const exist = await this.fetchPerson(uri);
|
||||||
if (exist) return exist;
|
if (exist) return exist;
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
|
|
||||||
const tokens = await query.getMany();
|
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 packedUsers = await this.userEntityService.packMany(Array.from(users.values()), me);
|
||||||
const packedUserMap = new Map(packedUsers.map(u => [u.id, u]));
|
const packedUserMap = new Map(packedUsers.map(u => [u.id, u]));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
// Validate grantees
|
// Validate grantees
|
||||||
if (ps.grantees && ps.grantees.length > 0) {
|
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) {
|
if (grantees.size !== ps.grantees.length) {
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
throw new ApiError(meta.errors.noSuchUser);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue