diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2022-03-08 22:56:46 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2022-03-08 22:56:46 +0900 |
| commit | b929bffea5301b98e3a6c6775cd77823d113bba0 (patch) | |
| tree | 1555fd743df7c85e140bd6262e338ab3a679e7d3 /packages/backend/src/services/chart | |
| parent | update deps (diff) | |
| download | misskey-b929bffea5301b98e3a6c6775cd77823d113bba0.tar.gz misskey-b929bffea5301b98e3a6c6775cd77823d113bba0.tar.bz2 misskey-b929bffea5301b98e3a6c6775cd77823d113bba0.zip | |
fix federation chart
Diffstat (limited to 'packages/backend/src/services/chart')
| -rw-r--r-- | packages/backend/src/services/chart/charts/entities/federation.ts | 3 | ||||
| -rw-r--r-- | packages/backend/src/services/chart/charts/federation.ts | 35 |
2 files changed, 29 insertions, 9 deletions
diff --git a/packages/backend/src/services/chart/charts/entities/federation.ts b/packages/backend/src/services/chart/charts/entities/federation.ts index c6d59b67f6..a8466b0b4c 100644 --- a/packages/backend/src/services/chart/charts/entities/federation.ts +++ b/packages/backend/src/services/chart/charts/entities/federation.ts @@ -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); diff --git a/packages/backend/src/services/chart/charts/federation.ts b/packages/backend/src/services/chart/charts/federation.ts index 2a28500ace..10221ee1e3 100644 --- a/packages/backend/src/services/chart/charts/federation.ts +++ b/packages/backend/src/services/chart/charts/federation.ts @@ -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, }; } |