summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/federation
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-06-28 13:05:20 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2022-06-28 13:05:20 +0900
commit5c3e782d29a16b4f13d2b372224f7a650b98be81 (patch)
tree36932814315ed81d9b84a4c60fc13b766fc579bd /packages/backend/src/server/api/endpoints/federation
parentchore(client): tweak style (diff)
downloadsharkey-5c3e782d29a16b4f13d2b372224f7a650b98be81.tar.gz
sharkey-5c3e782d29a16b4f13d2b372224f7a650b98be81.tar.bz2
sharkey-5c3e782d29a16b4f13d2b372224f7a650b98be81.zip
improve instance doughnut charts
Diffstat (limited to 'packages/backend/src/server/api/endpoints/federation')
-rw-r--r--packages/backend/src/server/api/endpoints/federation/stats.ts21
1 files changed, 18 insertions, 3 deletions
diff --git a/packages/backend/src/server/api/endpoints/federation/stats.ts b/packages/backend/src/server/api/endpoints/federation/stats.ts
index 5769996706..d3c2659088 100644
--- a/packages/backend/src/server/api/endpoints/federation/stats.ts
+++ b/packages/backend/src/server/api/endpoints/federation/stats.ts
@@ -1,5 +1,5 @@
-import { MoreThan } from 'typeorm';
-import { Instances } from '@/models/index.js';
+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';
@@ -21,7 +21,7 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps) => {
- const [topSubInstances, topPubInstances] = await Promise.all([
+ const [topSubInstances, topPubInstances, allSubCount, allPubCount] = await Promise.all([
Instances.find({
where: {
followersCount: MoreThan(0),
@@ -40,10 +40,25 @@ export default define(meta, paramDef, async (ps) => {
},
take: 10,
}),
+ Followings.count({
+ where: {
+ followeeHost: Not(IsNull()),
+ },
+ }),
+ Followings.count({
+ where: {
+ followerHost: Not(IsNull()),
+ },
+ }),
]);
+ const gotSubCount = topSubInstances.map(x => x.followersCount).reduce((a, b) => a + b, 0);
+ const gotPubCount = topSubInstances.map(x => x.followingCount).reduce((a, b) => a + b, 0);
+
return await awaitAll({
topSubInstances: Instances.packMany(topSubInstances),
+ otherFollowersCount: Math.max(0, allSubCount - gotSubCount),
topPubInstances: Instances.packMany(topPubInstances),
+ otherFollowingCount: Math.max(0, allPubCount - gotPubCount),
});
});