File tree Expand file tree Collapse file tree 1 file changed +20
-17
lines changed
Expand file tree Collapse file tree 1 file changed +20
-17
lines changed Original file line number Diff line number Diff line change @@ -95,23 +95,26 @@ new client.Gauge({
9595 help : 'Number of spaces per status' ,
9696 labelNames : [ 'status' ] ,
9797 async collect ( ) {
98- const statuses = {
99- verified : 'verified' ,
100- flagged : 'flagged' ,
101- turbo : 'turbo_expiration' ,
102- hibernated : 'hibernated'
103- } ;
104-
105- Object . entries ( statuses ) . forEach ( async ( [ status , column ] ) => {
106- this . set (
107- { status } ,
108- (
109- await db . queryAsync (
110- `SELECT COUNT(id) as count FROM spaces WHERE ${ column } > 0`
111- )
112- ) [ 0 ] . count
113- ) ;
114- } ) ;
98+ const statusQueries = [
99+ { status : 'verified' , column : 'verified' , pivot : 0 } ,
100+ { status : 'flagged' , column : 'flagged' , pivot : 0 } ,
101+ {
102+ status : 'turbo' ,
103+ column : 'turbo_expiration' ,
104+ pivot : Math . floor ( Date . now ( ) / 1000 )
105+ } ,
106+ { status : 'hibernated' , column : 'hibernated' , pivot : 0 }
107+ ] ;
108+
109+ await Promise . all (
110+ statusQueries . map ( async ( { status, column, pivot } ) => {
111+ const [ { count } ] = await db . queryAsync (
112+ `SELECT COUNT(id) as count FROM spaces WHERE ${ column } > ?` ,
113+ [ pivot ]
114+ ) ;
115+ this . set ( { status } , count ) ;
116+ } )
117+ ) ;
115118 }
116119} ) ;
117120
You can’t perform that action at this time.
0 commit comments