feat: add pub & sub item for federation chart
This commit is contained in:
		
							parent
							
								
									65be8daa15
								
							
						
					
					
						commit
						a28daf7f44
					
				
					 5 changed files with 49 additions and 14 deletions
				
			
		|  | @ -0,0 +1,15 @@ | |||
| const { MigrationInterface, QueryRunner } = require("typeorm"); | ||||
| 
 | ||||
| module.exports = class federationChartPubsub1645599900873 { | ||||
|     name = 'federationChartPubsub1645599900873' | ||||
| 
 | ||||
|     async up(queryRunner) { | ||||
|         await queryRunner.query(`ALTER TABLE "__chart__federation" ADD "___pubsub" smallint NOT NULL DEFAULT '0'`); | ||||
|         await queryRunner.query(`ALTER TABLE "__chart_day__federation" ADD "___pubsub" smallint NOT NULL DEFAULT '0'`); | ||||
|     } | ||||
| 
 | ||||
|     async down(queryRunner) { | ||||
|         await queryRunner.query(`ALTER TABLE "__chart_day__federation" DROP COLUMN "___pubsub"`); | ||||
|         await queryRunner.query(`ALTER TABLE "__chart__federation" DROP COLUMN "___pubsub"`); | ||||
|     } | ||||
| } | ||||
|  | @ -8,6 +8,7 @@ export const schema = { | |||
| 	'stalled': { uniqueIncrement: true, range: 'small' }, | ||||
| 	'sub': { accumulate: true, range: 'small' }, | ||||
| 	'pub': { accumulate: true, range: 'small' }, | ||||
| 	'pubsub': { accumulate: true, range: 'small' }, | ||||
| } as const; | ||||
| 
 | ||||
| export const entity = Chart.schemaToEntity(name, schema); | ||||
|  |  | |||
|  | @ -20,7 +20,11 @@ export default class FederationChart extends Chart<typeof schema> { | |||
| 
 | ||||
| 	@autobind | ||||
| 	protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> { | ||||
| 		const [sub, pub] = await Promise.all([ | ||||
| 		const pubsubSubQuery = Followings.createQueryBuilder('f') | ||||
| 			.select('f.followerHost') | ||||
| 			.where('f.followerHost IS NOT NULL'); | ||||
| 
 | ||||
| 		const [sub, pub, pubsub] = await Promise.all([ | ||||
| 			Followings.createQueryBuilder('following') | ||||
| 				.select('COUNT(DISTINCT following.followeeHost)') | ||||
| 				.where('following.followeeHost IS NOT NULL') | ||||
|  | @ -31,11 +35,19 @@ export default class FederationChart extends Chart<typeof schema> { | |||
| 				.where('following.followerHost IS NOT NULL') | ||||
| 				.getRawOne() | ||||
| 				.then(x => parseInt(x.count, 10)), | ||||
| 			Followings.createQueryBuilder('following') | ||||
| 				.select('COUNT(DISTINCT following.followeeHost)') | ||||
| 				.where('following.followeeHost IS NOT NULL') | ||||
| 				.andWhere(`following.followerHost IN (${ pubsubSubQuery.getQuery() })`) | ||||
| 				.setParameters(pubsubSubQuery.getParameters()) | ||||
| 				.getRawOne() | ||||
| 				.then(x => parseInt(x.count, 10)), | ||||
| 		]); | ||||
| 
 | ||||
| 		return { | ||||
| 			'sub': sub, | ||||
| 			'pub': pub, | ||||
| 			'pubsub': pubsub, | ||||
| 		}; | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue