import autobind from 'autobind-decorator'; import Chart, { KVs } from '../core'; import { Followings } from '@/models/index'; import { name, schema } from './entities/federation'; /** * フェデレーションに関するチャート */ // eslint-disable-next-line import/no-default-export export default class FederationChart extends Chart { constructor() { super(name, schema); } @autobind protected async tickMajor(): Promise>> { return { }; } @autobind protected async tickMinor(): Promise>> { const [sub, pub] = await Promise.all([ Followings.createQueryBuilder('following') .select('COUNT(DISTINCT following.followeeHost)') .where('following.followeeHost IS NOT NULL') .getRawOne() .then(x => parseInt(x.count, 10)), Followings.createQueryBuilder('following') .select('COUNT(DISTINCT following.followerHost)') .where('following.followerHost IS NOT NULL') .getRawOne() .then(x => parseInt(x.count, 10)), ]); return { 'sub': sub, 'pub': pub, }; } @autobind public async deliverd(host: string, succeeded: boolean): Promise { await this.commit(succeeded ? { 'deliveredInstances': [host], } : { 'stalled': [host], }); } @autobind public async inbox(host: string): Promise { await this.commit({ 'inboxInstances': [host], }); } }