なんかもうめっちゃ変えた
This commit is contained in:
parent
d9ab03f086
commit
b75184ec8e
946 changed files with 41219 additions and 28839 deletions
|
@ -1,7 +1,10 @@
|
|||
import { IsNull, MoreThan, Not } from 'typeorm';
|
||||
import { Followings, Instances } from '@/models/index.js';
|
||||
import { awaitAll } from '@/prelude/await-all.js';
|
||||
import define from '../../define.js';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { FollowingsRepository, InstancesRepository } from '@/models/index.js';
|
||||
import { awaitAll } from '@/misc/prelude/await-all.js';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { InstanceEntityService } from '@/core/entities/InstanceEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['federation'],
|
||||
|
@ -21,45 +24,58 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
const [topSubInstances, topPubInstances, allSubCount, allPubCount] = await Promise.all([
|
||||
Instances.find({
|
||||
where: {
|
||||
followersCount: MoreThan(0),
|
||||
},
|
||||
order: {
|
||||
followersCount: 'DESC',
|
||||
},
|
||||
take: ps.limit,
|
||||
}),
|
||||
Instances.find({
|
||||
where: {
|
||||
followingCount: MoreThan(0),
|
||||
},
|
||||
order: {
|
||||
followingCount: 'DESC',
|
||||
},
|
||||
take: ps.limit,
|
||||
}),
|
||||
Followings.count({
|
||||
where: {
|
||||
followeeHost: Not(IsNull()),
|
||||
},
|
||||
}),
|
||||
Followings.count({
|
||||
where: {
|
||||
followerHost: Not(IsNull()),
|
||||
},
|
||||
}),
|
||||
]);
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
constructor(
|
||||
@Inject(DI.instancesRepository)
|
||||
private instancesRepository: InstancesRepository,
|
||||
|
||||
const gotSubCount = topSubInstances.map(x => x.followersCount).reduce((a, b) => a + b, 0);
|
||||
const gotPubCount = topPubInstances.map(x => x.followingCount).reduce((a, b) => a + b, 0);
|
||||
@Inject(DI.followingsRepository)
|
||||
private followingsRepository: FollowingsRepository,
|
||||
|
||||
return await awaitAll({
|
||||
topSubInstances: Instances.packMany(topSubInstances),
|
||||
otherFollowersCount: Math.max(0, allSubCount - gotSubCount),
|
||||
topPubInstances: Instances.packMany(topPubInstances),
|
||||
otherFollowingCount: Math.max(0, allPubCount - gotPubCount),
|
||||
});
|
||||
});
|
||||
private instanceEntityService: InstanceEntityService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const [topSubInstances, topPubInstances, allSubCount, allPubCount] = await Promise.all([
|
||||
this.instancesRepository.find({
|
||||
where: {
|
||||
followersCount: MoreThan(0),
|
||||
},
|
||||
order: {
|
||||
followersCount: 'DESC',
|
||||
},
|
||||
take: ps.limit,
|
||||
}),
|
||||
this.instancesRepository.find({
|
||||
where: {
|
||||
followingCount: MoreThan(0),
|
||||
},
|
||||
order: {
|
||||
followingCount: 'DESC',
|
||||
},
|
||||
take: ps.limit,
|
||||
}),
|
||||
this.followingsRepository.count({
|
||||
where: {
|
||||
followeeHost: Not(IsNull()),
|
||||
},
|
||||
}),
|
||||
this.followingsRepository.count({
|
||||
where: {
|
||||
followerHost: Not(IsNull()),
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
const gotSubCount = topSubInstances.map(x => x.followersCount).reduce((a, b) => a + b, 0);
|
||||
const gotPubCount = topPubInstances.map(x => x.followingCount).reduce((a, b) => a + b, 0);
|
||||
|
||||
return await awaitAll({
|
||||
topSubInstances: this.instanceEntityService.packMany(topSubInstances),
|
||||
otherFollowersCount: Math.max(0, allSubCount - gotSubCount),
|
||||
topPubInstances: this.instanceEntityService.packMany(topPubInstances),
|
||||
otherFollowingCount: Math.max(0, allPubCount - gotPubCount),
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue