fix federation chart

This commit is contained in:
syuilo
2022-03-08 22:56:46 +09:00
parent 45c5f0c60a
commit b929bffea5
4 changed files with 59 additions and 13 deletions

View File

@ -9,7 +9,8 @@ export const schema = {
'sub': { accumulate: true, range: 'small' },
'pub': { accumulate: true, range: 'small' },
'pubsub': { accumulate: true, range: 'small' },
'active': { accumulate: true, range: 'small' },
'subActive': { accumulate: true, range: 'small' },
'pubActive': { accumulate: true, range: 'small' },
} as const;
export const entity = Chart.schemaToEntity(name, schema);

View File

@ -2,7 +2,6 @@ import Chart, { KVs } from '../core.js';
import { Followings, Instances } from '@/models/index.js';
import { name, schema } from './entities/federation.js';
import { fetchMeta } from '@/misc/fetch-meta.js';
import { In, MoreThan, Not } from 'typeorm';
/**
* フェデレーションに関するチャート
@ -29,7 +28,15 @@ export default class FederationChart extends Chart<typeof schema> {
.select('f.followerHost')
.where('f.followerHost IS NOT NULL');
const [sub, pub, pubsub, active] = await Promise.all([
const subInstancesQuery = Followings.createQueryBuilder('f')
.select('f.followeeHost')
.where('f.followeeHost IS NOT NULL');
const pubInstancesQuery = Followings.createQueryBuilder('f')
.select('f.followerHost')
.where('f.followerHost IS NOT NULL');
const [sub, pub, pubsub, subActive, pubActive] = await Promise.all([
Followings.createQueryBuilder('following')
.select('COUNT(DISTINCT following.followeeHost)')
.where('following.followeeHost IS NOT NULL')
@ -53,18 +60,30 @@ export default class FederationChart extends Chart<typeof schema> {
.setParameters(pubsubSubQuery.getParameters())
.getRawOne()
.then(x => parseInt(x.count, 10)),
Instances.count({
host: Not(In(meta.blockedHosts)),
isSuspended: false,
lastCommunicatedAt: MoreThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 30))),
}),
Instances.createQueryBuilder('instance')
.select('COUNT(instance.id)')
.where(`instance.host IN (${ subInstancesQuery.getQuery() })`)
.andWhere(meta.blockedHosts.length === 0 ? '1=1' : `instance.host NOT IN (:...blocked)`, { blocked: meta.blockedHosts })
.andWhere(`instance.isSuspended = false`)
.andWhere(`instance.lastCommunicatedAt > :gt`, { gt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 30)) })
.getRawOne()
.then(x => parseInt(x.count, 10)),
Instances.createQueryBuilder('instance')
.select('COUNT(instance.id)')
.where(`instance.host IN (${ pubInstancesQuery.getQuery() })`)
.andWhere(meta.blockedHosts.length === 0 ? '1=1' : `instance.host NOT IN (:...blocked)`, { blocked: meta.blockedHosts })
.andWhere(`instance.isSuspended = false`)
.andWhere(`instance.lastCommunicatedAt > :gt`, { gt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 30)) })
.getRawOne()
.then(x => parseInt(x.count, 10)),
]);
return {
'sub': sub,
'pub': pub,
'pubsub': pubsub,
'active': active,
'subActive': subActive,
'pubActive': pubActive,
};
}