use cache when resolving user for updateFeatured
This commit is contained in:
parent
2514ebd166
commit
09ef662444
1 changed files with 29 additions and 14 deletions
|
|
@ -916,23 +916,19 @@ export class ApPersonService implements OnModuleInit {
|
||||||
* Duplicate updates are automatically skipped.
|
* Duplicate updates are automatically skipped.
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public async updateFeaturedLazy(userOrId: MiUser | MiUser['id']): Promise<void> {
|
public async updateFeaturedLazy(userOrId: MiRemoteUser | MiUser['id']): Promise<void> {
|
||||||
const userId = typeof(userOrId) === 'object' ? userOrId.id : userOrId;
|
const user = await this.resolveUserForFeatured(userOrId);
|
||||||
const user = typeof(userOrId) === 'object' ? userOrId : await this.usersRepository.findOneByOrFail({ id: userId, isDeleted: false });
|
if (!user) return;
|
||||||
|
|
||||||
if (isRemoteUser(user) && user.featured) {
|
await this.queueService.createUpdateFeaturedJob(user.id);
|
||||||
await this.queueService.createUpdateFeaturedJob(userId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async updateFeatured(userOrId: MiUser | MiUser['id'], resolver?: Resolver): Promise<void> {
|
public async updateFeatured(userOrId: MiRemoteUser | MiUser['id'], resolver?: Resolver): Promise<void> {
|
||||||
const userId = typeof(userOrId) === 'object' ? userOrId.id : userOrId;
|
const user = await this.resolveUserForFeatured(userOrId);
|
||||||
const user = typeof(userOrId) === 'object' ? userOrId : await this.usersRepository.findOneByOrFail({ id: userId, isDeleted: false });
|
if (!user) return;
|
||||||
if (!isRemoteUser(user)) return;
|
|
||||||
if (!user.featured) return;
|
|
||||||
|
|
||||||
this.logger.info(`Updating the featured: ${user.uri}`);
|
this.logger.info(`Updating featured notes for: ${user.uri}`);
|
||||||
|
|
||||||
resolver ??= this.apResolverService.createResolver();
|
resolver ??= this.apResolverService.createResolver();
|
||||||
|
|
||||||
|
|
@ -948,8 +944,8 @@ export class ApPersonService implements OnModuleInit {
|
||||||
sentFrom: itemId, // resolveCollectionItems has already verified this, so we can re-use it to avoid double fetch
|
sentFrom: itemId, // resolveCollectionItems has already verified this, so we can re-use it to avoid double fetch
|
||||||
});
|
});
|
||||||
|
|
||||||
if (note && note.userId !== userId) {
|
if (note && note.userId !== user.id) {
|
||||||
this.logger.warn(`Ignoring cross-note pin: user ${userId} tried to pin note ${note.id} belonging to user ${note.userId}`);
|
this.logger.warn(`Ignoring cross-note pin: user ${user.id} tried to pin note ${note.id} belonging to other user ${note.userId}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -979,6 +975,25 @@ export class ApPersonService implements OnModuleInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@bindThis
|
||||||
|
private async resolveUserForFeatured(userOrId: MiRemoteUser | MiUser['id']): Promise<(MiRemoteUser & { featured: string }) | null> {
|
||||||
|
const userId = typeof(userOrId) === 'object' ? userOrId.id : userOrId;
|
||||||
|
const user = typeof(userOrId) === 'object' ? userOrId : await this.cacheService.findRemoteUserById(userId);
|
||||||
|
|
||||||
|
if (user.isDeleted || user.isSuspended) {
|
||||||
|
this.logger.debug(`Not updating featured for ${userId}: user is deleted`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user.featured) {
|
||||||
|
this.logger.debug(`Not updating featured for ${userId}: no featured collection`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For some reason TS doesn't recognize the type check above.
|
||||||
|
return user as MiRemoteUser & { featured: string };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* リモート由来のアカウント移行処理を行います
|
* リモート由来のアカウント移行処理を行います
|
||||||
* @param src 移行元アカウント(リモートかつupdatePerson後である必要がある、というかこれ自体がupdatePersonで呼ばれる前提)
|
* @param src 移行元アカウント(リモートかつupdatePerson後である必要がある、というかこれ自体がupdatePersonで呼ばれる前提)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue