@@ -53,18 +53,12 @@ function loadData(path: string | null) {
53
53
}
54
54
}
55
55
56
- type SuspectReqs = Partial < { elo : number , gxe : number , coil : number } > ;
57
- const suspects : Record < string , { startDate : number , reqs : SuspectReqs } > = loadData ( Config . suspectpath ) ;
58
- const coil : Record < string , number > = loadData ( Config . coilpath ) ;
59
-
60
- if ( Config . suspectpath ) {
61
- watchFile (
62
- Config . suspectpath ,
63
- ( ) => Object . assign ( suspects , loadData ( Config . suspectpath ) )
64
- ) ;
65
- }
56
+ export let coil : Record < string , number > = loadData ( Config . coilpath ) ;
57
+
66
58
if ( Config . coilpath ) {
67
- watchFile ( Config . coilpath , ( ) => Object . assign ( coil , loadData ( Config . coilpath ) ) ) ;
59
+ watchFile ( Config . coilpath , ( ) => {
60
+ coil = loadData ( Config . coilpath ) ;
61
+ } ) ;
68
62
}
69
63
70
64
const redundantFetch = async ( targetUrl : string , data : RequestInit , attempts = 0 ) : Promise < void > => {
@@ -374,8 +368,9 @@ export const actions: {[k: string]: QueryHandler} = {
374
368
const out : { [ k : string ] : any } = { } ;
375
369
const [ p1rating , p2rating ] = await ladder . addMatch ( params . p1 ! , params . p2 ! , parseFloat ( params . score ) ) ;
376
370
377
- if ( suspects [ formatid ] ) {
378
- const reqs = suspects [ formatid ] . reqs ;
371
+ const suspect = await tables . suspects . get ( formatid ) ;
372
+ if ( suspect ) {
373
+ const reqs = { elo : suspect . elo , gxe : suspect . gxe , coil : suspect . gxe } ;
379
374
for ( const rating of [ p1rating , p2rating ] ) {
380
375
let reqsMet = 0 ;
381
376
let reqCount = 0 ;
@@ -405,13 +400,13 @@ export const actions: {[k: string]: QueryHandler} = {
405
400
// sanity check for reqs existing just to be totally safe
406
401
( reqsMet >= 1 && reqsMet === reqCount ) &&
407
402
// did not play games before the test began
408
- ( ratingData ?. first_played && ratingData . first_played > suspects [ formatid ] . startDate )
403
+ ( ratingData ?. first_played && ratingData . first_played > suspect . start_date )
409
404
) {
410
405
void smogonFetch ( "tools/api/suspect-verify" , "POST" , {
411
406
userid : rating . userid ,
412
407
format : formatid ,
413
408
reqs : { required : reqs , actual : userData } ,
414
- suspectStartDate : suspects [ formatid ] . startDate ,
409
+ suspectStartDate : suspect . start_date ,
415
410
} ) ;
416
411
}
417
412
}
@@ -1061,13 +1056,13 @@ export const actions: {[k: string]: QueryHandler} = {
1061
1056
} catch ( e : any ) {
1062
1057
throw new ActionError ( "Failed to update Smogon suspect test record: " + e . message ) ;
1063
1058
}
1064
- suspects [ id ] = {
1065
- startDate : time ( ) ,
1066
- reqs ,
1067
- } ;
1068
- if ( Config . suspectpath ) {
1069
- await fs . writeFile ( Config . suspectpath , JSON . stringify ( suspects ) ) ;
1070
- }
1059
+ await tables . suspects . replace ( {
1060
+ formatid : id ,
1061
+ start_date : time ( ) ,
1062
+ elo : reqs . elo ,
1063
+ gxe : reqs . gxe ,
1064
+ coil : reqs . coil ,
1065
+ } ) ;
1071
1066
return { success : true } ;
1072
1067
} ,
1073
1068
async 'suspects/end' ( params ) {
@@ -1076,11 +1071,9 @@ export const actions: {[k: string]: QueryHandler} = {
1076
1071
}
1077
1072
const id = toID ( params . format ) ;
1078
1073
if ( ! id ) throw new ActionError ( "No format ID specified." ) ;
1079
- if ( ! suspects [ id ] ) throw new ActionError ( "There is no ongoing suspect for " + id ) ;
1080
- delete suspects [ id ] ;
1081
- if ( Config . suspectpath ) {
1082
- await fs . writeFile ( Config . suspectpath , JSON . stringify ( suspects ) ) ;
1083
- }
1074
+ const suspect = await tables . suspects . get ( id ) ;
1075
+ if ( ! suspect ) throw new ActionError ( "There is no ongoing suspect for " + id ) ;
1076
+ await tables . suspects . delete ( id ) ;
1084
1077
return { success : true } ;
1085
1078
} ,
1086
1079
} ;
0 commit comments