Skip to content

Commit 652f1a7

Browse files
authored
fix: remove undefined keys from the global networks count variable (#1029)
1 parent 8ae5d27 commit 652f1a7

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/helpers/metrics.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { capture } from '@snapshot-labs/snapshot-sentry';
33
import { Express, Request, Response } from 'express';
44
import { GraphQLError, parse } from 'graphql';
55
import db from './mysql';
6-
import { spacesMetadata } from './spaces';
6+
import { networkSpaceCounts, spacesMetadata } from './spaces';
77
import { strategies } from './strategies';
88
import operations from '../graphql/operations/';
99

@@ -122,16 +122,8 @@ new client.Gauge({
122122
help: 'Number of spaces per network',
123123
labelNames: ['network'],
124124
async collect() {
125-
const results = {};
126-
Object.values(spacesMetadata).forEach((space: any) => {
127-
space.networks.forEach(network => {
128-
results[network] ||= 0;
129-
results[network]++;
130-
});
131-
});
132-
133-
for (const r in results) {
134-
this.set({ network: r }, results[r]);
125+
for (const network in networkSpaceCounts) {
126+
this.set({ network }, networkSpaceCounts[network]);
135127
}
136128
}
137129
});

src/helpers/spaces.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,17 @@ function mapSpaces(spaces: Record<string, any>) {
104104
networkSpaceCounts = {};
105105

106106
Object.entries(spaces).forEach(([id, space]: any) => {
107-
const networks = uniq([
108-
space.network,
109-
...space.strategies.map((strategy: any) => strategy.network),
110-
...space.strategies.flatMap((strategy: any) =>
111-
Array.isArray(strategy.params?.strategies)
112-
? strategy.params.strategies.map((param: any) => param.network)
113-
: []
114-
)
115-
]);
107+
const networks = uniq(
108+
[
109+
space.network,
110+
...space.strategies.map((strategy: any) => strategy.network),
111+
...space.strategies.flatMap((strategy: any) =>
112+
Array.isArray(strategy.params?.strategies)
113+
? strategy.params.strategies.map((param: any) => param.network)
114+
: []
115+
)
116+
].filter(Boolean)
117+
);
116118

117119
networks.forEach(network => {
118120
networkSpaceCounts[network] = (networkSpaceCounts[network] || 0) + 1;

0 commit comments

Comments
 (0)