2022-02-27 03:07:39 +01:00
|
|
|
import Chart, { KVs } from '../core.js';
|
|
|
|
import { Followings } from '@/models/index.js';
|
|
|
|
import { name, schema } from './entities/federation.js';
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2021-12-14 10:12:37 +01:00
|
|
|
/**
|
|
|
|
* フェデレーションに関するチャート
|
|
|
|
*/
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-05 16:13:52 +01:00
|
|
|
export default class FederationChart extends Chart<typeof schema> {
|
2019-04-07 14:50:36 +02:00
|
|
|
constructor() {
|
|
|
|
super(name, schema);
|
|
|
|
}
|
|
|
|
|
2022-02-10 09:45:12 +01:00
|
|
|
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
2019-04-07 14:50:36 +02:00
|
|
|
return {
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-10 09:45:12 +01:00
|
|
|
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
2022-02-23 08:17:16 +01:00
|
|
|
const pubsubSubQuery = Followings.createQueryBuilder('f')
|
|
|
|
.select('f.followerHost')
|
|
|
|
.where('f.followerHost IS NOT NULL');
|
|
|
|
|
|
|
|
const [sub, pub, pubsub] = await Promise.all([
|
2022-02-10 09:45:12 +01:00
|
|
|
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)),
|
2022-02-23 08:17:16 +01:00
|
|
|
Followings.createQueryBuilder('following')
|
|
|
|
.select('COUNT(DISTINCT following.followeeHost)')
|
|
|
|
.where('following.followeeHost IS NOT NULL')
|
2022-03-04 07:32:50 +01:00
|
|
|
.andWhere(`following.followeeHost IN (${ pubsubSubQuery.getQuery() })`)
|
2022-02-23 08:17:16 +01:00
|
|
|
.setParameters(pubsubSubQuery.getParameters())
|
|
|
|
.getRawOne()
|
|
|
|
.then(x => parseInt(x.count, 10)),
|
2022-02-10 09:45:12 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
return {
|
|
|
|
'sub': sub,
|
|
|
|
'pub': pub,
|
2022-02-23 08:17:16 +01:00
|
|
|
'pubsub': pubsub,
|
2022-02-10 09:45:12 +01:00
|
|
|
};
|
2022-02-05 16:13:52 +01:00
|
|
|
}
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2022-02-08 15:43:51 +01:00
|
|
|
public async deliverd(host: string, succeeded: boolean): Promise<void> {
|
|
|
|
await this.commit(succeeded ? {
|
2022-02-05 16:13:52 +01:00
|
|
|
'deliveredInstances': [host],
|
2022-02-08 15:43:51 +01:00
|
|
|
} : {
|
|
|
|
'stalled': [host],
|
2022-02-05 16:13:52 +01:00
|
|
|
});
|
|
|
|
}
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2022-02-05 16:13:52 +01:00
|
|
|
public async inbox(host: string): Promise<void> {
|
|
|
|
await this.commit({
|
|
|
|
'inboxInstances': [host],
|
2019-04-07 14:50:36 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|