0
0

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

@ -0,0 +1,21 @@
export class chartFederationActiveSubPub1646732390560 {
name = 'chartFederationActiveSubPub1646732390560'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "__chart__federation" DROP COLUMN "___active"`);
await queryRunner.query(`ALTER TABLE "__chart_day__federation" DROP COLUMN "___active"`);
await queryRunner.query(`ALTER TABLE "__chart__federation" ADD "___subActive" smallint NOT NULL DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE "__chart__federation" ADD "___pubActive" smallint NOT NULL DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE "__chart_day__federation" ADD "___subActive" smallint NOT NULL DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE "__chart_day__federation" ADD "___pubActive" smallint NOT NULL DEFAULT '0'`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "__chart_day__federation" DROP COLUMN "___pubActive"`);
await queryRunner.query(`ALTER TABLE "__chart_day__federation" DROP COLUMN "___subActive"`);
await queryRunner.query(`ALTER TABLE "__chart__federation" DROP COLUMN "___pubActive"`);
await queryRunner.query(`ALTER TABLE "__chart__federation" DROP COLUMN "___subActive"`);
await queryRunner.query(`ALTER TABLE "__chart_day__federation" ADD "___active" smallint NOT NULL DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE "__chart__federation" ADD "___active" smallint NOT NULL DEFAULT '0'`);
}
}

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,
};
}

View File

@ -70,7 +70,7 @@ const colors = {
red: '#FF4560',
purple: '#e300db',
orange: '#fe6919',
lime: '#c7f400',
lime: '#bde800',
cyan: '#00efef',
};
const colorSets = [colors.blue, colors.green, colors.yellow, colors.red, colors.purple];
@ -390,10 +390,15 @@ export default defineComponent({
data: format(raw.stalled),
color: colors.red,
}, {
name: 'Active',
name: 'Pub Active',
type: 'line',
data: format(raw.active),
color: colors.lime,
data: format(raw.pubActive),
color: colors.purple,
}, {
name: 'Sub Active',
type: 'line',
data: format(raw.subActive),
color: colors.orange,
}, {
name: 'Pub & Sub',
type: 'line',