Skip to content

Commit 20bbf0e

Browse files
committed
fix: fix metrics for spaces status
1 parent 431e256 commit 20bbf0e

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/helpers/metrics.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)