File tree Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -95,15 +95,24 @@ new client.Gauge({
95
95
help : 'Number of spaces per status' ,
96
96
labelNames : [ 'status' ] ,
97
97
async collect ( ) {
98
- [ 'verified' , 'flagged' , 'turbo' , 'hibernated' ] . forEach ( async status => {
99
- this . set (
100
- { status } ,
101
- (
102
- await db . queryAsync (
103
- `SELECT COUNT(id) as count FROM spaces WHERE ${ status } > 0`
104
- )
105
- ) [ 0 ] . count
106
- ) ;
98
+ const statusResults = await db . queryAsync ( `
99
+ SELECT
100
+ SUM(CASE WHEN verified > 0 THEN 1 ELSE 0 END) AS verified,
101
+ SUM(CASE WHEN flagged > 0 THEN 1 ELSE 0 END) AS flagged,
102
+ SUM(CASE WHEN hibernated > 0 THEN 1 ELSE 0 END) AS hibernated,
103
+ SUM(CASE WHEN turbo_expiration > UNIX_TIMESTAMP() THEN 1 ELSE 0 END) AS active_turbo,
104
+ SUM(CASE WHEN turbo_expiration > 0 AND turbo_expiration <= UNIX_TIMESTAMP() THEN 1 ELSE 0 END) AS expired_turbo
105
+ FROM spaces
106
+ ` ) ;
107
+
108
+ [
109
+ 'verified' ,
110
+ 'flagged' ,
111
+ 'hibernated' ,
112
+ 'active_turbo' ,
113
+ 'expired_turbo'
114
+ ] . forEach ( status => {
115
+ this . set ( { status } , statusResults [ 0 ] [ status ] ) ;
107
116
} ) ;
108
117
}
109
118
} ) ;
You can’t perform that action at this time.
0 commit comments