11import { LogTag } from '@-xun/cli/logging' ;
2- import { getDb } from '@-xun/mongo-schema' ;
2+ import { getClient , getDb , setSchemaConfig } from '@-xun/mongo-schema' ;
33import { runWithMongoSchemaMultitenancy } from '@-xun/mongo-schema/multitenant' ;
44
5- import { oneSecondInMs , TargetProblem , Task } from 'universe:constant.ts' ;
5+ import {
6+ oneSecondInMs ,
7+ TargetProblem ,
8+ targetProblemBackends ,
9+ Task
10+ } from 'universe:constant.ts' ;
11+
612import { ErrorMessage } from 'universe:error.ts' ;
713import { skipListrTask , waitForListr2OutputReady } from 'universe:util.ts' ;
814
915import type { GlobalExecutionContext } from 'universe:configure.ts' ;
1016import type { ActualTargetProblem } from 'universe:constant.ts' ;
1117import type { TaskRunnerContext } from 'universe:util.ts' ;
1218
13- const fullPrettyName = 'ban hammer' ;
14- const taskType = Task . BanHammer ;
19+ export const fullPrettyName = 'ban hammer' ;
20+ export const taskType = Task . BanHammer ;
1521
1622export default async function task (
1723 taskName : string ,
@@ -26,7 +32,9 @@ export default async function task(
2632
2733 await waitForListr2OutputReady ( debug ) ;
2834
29- await runWithMongoSchemaMultitenancy ( target , async ( ) => {
35+ await runWithMongoSchemaMultitenancy ( `${ target } -${ taskType } ` , async ( ) => {
36+ let backend ;
37+
3038 switch ( target ) {
3139 case TargetProblem . ElectionsCpl :
3240 case TargetProblem . ElectionsIrv :
@@ -41,8 +49,13 @@ export default async function task(
4149 return ;
4250 }
4351
44- case TargetProblem . Drive :
52+ case TargetProblem . Drive : {
53+ backend = await targetProblemBackends . drive ;
54+ break ;
55+ }
56+
4557 case TargetProblem . Qoverflow : {
58+ backend = await targetProblemBackends . qoverflow ;
4659 break ;
4760 }
4861
@@ -51,8 +64,16 @@ export default async function task(
5164 }
5265 }
5366
54- const bannedCount = await unleashBanHammer ( ) ;
67+ // ? Prewarm shared memory
68+ await getClient ( {
69+ MONGODB_URI : getConfig ( `${ target } .mongodbUri` , 'string' )
70+ } ) ;
5571
72+ setSchemaConfig ( backend . db . getSchemaConfig ( ) ) ;
73+
74+ const [ bannedCount , cursor ] = await unleashBanHammer ( ) ;
75+
76+ await cursor . close ( ) ;
5677 taskLog ( [ LogTag . IF_NOT_QUIETED ] , '~%O clients are currently banned' , bannedCount ) ;
5778 } ) ;
5879
@@ -273,11 +294,9 @@ export default async function task(
273294 debug ( 'aggregation pipeline: %O' , pipeline ) ;
274295
275296 const cursor = db . collection ( 'request-log' ) . aggregate ( pipeline ) ;
297+ await cursor . toArray ( ) ;
276298
277- await cursor . next ( ) ;
278- await cursor . close ( ) ;
279-
280- return db . collection ( 'limited-log' ) . estimatedDocumentCount ( ) ;
299+ return [ db . collection ( 'limited-log' ) . estimatedDocumentCount ( ) , cursor ] as const ;
281300 }
282301
283302 function getConfigFor ( target : ActualTargetProblem ) {
0 commit comments