Skip to content

Commit 8ae5d27

Browse files
authored
fix: use new expiration column to return turbo status (#1030)
1 parent 4f38552 commit 8ae5d27

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/helpers/metrics.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,24 @@ new client.Gauge({
9595
help: 'Number of spaces per status',
9696
labelNames: ['status'],
9797
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]);
107116
});
108117
}
109118
});

0 commit comments

Comments
 (0)