refactor
This commit is contained in:
parent
67ca7ee4ec
commit
a78a839841
|
@ -58,12 +58,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
private activeUsersChart: ActiveUsersChart,
|
private activeUsersChart: ActiveUsersChart,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
const hasFollowing = (await this.followingsRepository.count({
|
const followees = await this.followingsRepository.createQueryBuilder('following')
|
||||||
where: {
|
.select('following.followeeId')
|
||||||
followerId: me.id,
|
.where('following.followerId = :followerId', { followerId: me.id })
|
||||||
},
|
.getMany();
|
||||||
take: 1,
|
|
||||||
})) !== 0;
|
|
||||||
|
|
||||||
//#region Construct query
|
//#region Construct query
|
||||||
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
|
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
|
||||||
|
@ -81,11 +79,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
||||||
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner');
|
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner');
|
||||||
|
|
||||||
if (hasFollowing) {
|
if (followees.length > 0) {
|
||||||
const followees = await this.followingsRepository.createQueryBuilder('following')
|
|
||||||
.select('following.followeeId')
|
|
||||||
.where('following.followerId = :followerId', { followerId: me.id })
|
|
||||||
.getMany();
|
|
||||||
const meOrFolloweeIds = [me.id, ...followees.map(f => f.followeeId)];
|
const meOrFolloweeIds = [me.id, ...followees.map(f => f.followeeId)];
|
||||||
|
|
||||||
query.andWhere('note.userId IN (:...meOrFolloweeIds)', { meOrFolloweeIds: meOrFolloweeIds });
|
query.andWhere('note.userId IN (:...meOrFolloweeIds)', { meOrFolloweeIds: meOrFolloweeIds });
|
||||||
|
|
Loading…
Reference in New Issue