enhance(chart): better federation pub/sub calculation

This commit is contained in:
syuilo 2022-03-04 16:26:10 +09:00
parent b67f1287c6
commit 271854e345
1 changed files with 14 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import Chart, { KVs } from '../core.js'; import Chart, { KVs } from '../core.js';
import { Followings } from '@/models/index.js'; import { Followings, Instances } from '@/models/index.js';
import { name, schema } from './entities/federation.js'; import { name, schema } from './entities/federation.js';
import { fetchMeta } from '@/misc/fetch-meta.js';
/** /**
* *
@ -17,6 +18,12 @@ export default class FederationChart extends Chart<typeof schema> {
} }
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> { protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
const meta = await fetchMeta();
const suspendedInstancesQuery = Instances.createQueryBuilder('instance')
.select('instance.host')
.where('instance.isSuspended = true');
const pubsubSubQuery = Followings.createQueryBuilder('f') const pubsubSubQuery = Followings.createQueryBuilder('f')
.select('f.followerHost') .select('f.followerHost')
.where('f.followerHost IS NOT NULL'); .where('f.followerHost IS NOT NULL');
@ -25,16 +32,22 @@ export default class FederationChart extends Chart<typeof schema> {
Followings.createQueryBuilder('following') Followings.createQueryBuilder('following')
.select('COUNT(DISTINCT following.followeeHost)') .select('COUNT(DISTINCT following.followeeHost)')
.where('following.followeeHost IS NOT NULL') .where('following.followeeHost IS NOT NULL')
.andWhere(`following.followeeHost NOT IN (:...blocked)`, { blocked: meta.blockedHosts })
.andWhere(`following.followeeHost NOT IN (${ suspendedInstancesQuery.getQuery() })`)
.getRawOne() .getRawOne()
.then(x => parseInt(x.count, 10)), .then(x => parseInt(x.count, 10)),
Followings.createQueryBuilder('following') Followings.createQueryBuilder('following')
.select('COUNT(DISTINCT following.followerHost)') .select('COUNT(DISTINCT following.followerHost)')
.where('following.followerHost IS NOT NULL') .where('following.followerHost IS NOT NULL')
.andWhere(`following.followerHost NOT IN (:...blocked)`, { blocked: meta.blockedHosts })
.andWhere(`following.followerHost NOT IN (${ suspendedInstancesQuery.getQuery() })`)
.getRawOne() .getRawOne()
.then(x => parseInt(x.count, 10)), .then(x => parseInt(x.count, 10)),
Followings.createQueryBuilder('following') Followings.createQueryBuilder('following')
.select('COUNT(DISTINCT following.followeeHost)') .select('COUNT(DISTINCT following.followeeHost)')
.where('following.followeeHost IS NOT NULL') .where('following.followeeHost IS NOT NULL')
.andWhere(`following.followeeHost NOT IN (:...blocked)`, { blocked: meta.blockedHosts })
.andWhere(`following.followeeHost NOT IN (${ suspendedInstancesQuery.getQuery() })`)
.andWhere(`following.followeeHost IN (${ pubsubSubQuery.getQuery() })`) .andWhere(`following.followeeHost IN (${ pubsubSubQuery.getQuery() })`)
.setParameters(pubsubSubQuery.getParameters()) .setParameters(pubsubSubQuery.getParameters())
.getRawOne() .getRawOne()