File tree Expand file tree Collapse file tree 2 files changed +14
-20
lines changed Expand file tree Collapse file tree 2 files changed +14
-20
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { capture } from '@snapshot-labs/snapshot-sentry';
3
3
import { Express , Request , Response } from 'express' ;
4
4
import { GraphQLError , parse } from 'graphql' ;
5
5
import db from './mysql' ;
6
- import { spacesMetadata } from './spaces' ;
6
+ import { networkSpaceCounts , spacesMetadata } from './spaces' ;
7
7
import { strategies } from './strategies' ;
8
8
import operations from '../graphql/operations/' ;
9
9
@@ -122,16 +122,8 @@ new client.Gauge({
122
122
help : 'Number of spaces per network' ,
123
123
labelNames : [ 'network' ] ,
124
124
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 ] ) ;
135
127
}
136
128
}
137
129
} ) ;
Original file line number Diff line number Diff line change @@ -104,15 +104,17 @@ function mapSpaces(spaces: Record<string, any>) {
104
104
networkSpaceCounts = { } ;
105
105
106
106
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
+ ) ;
116
118
117
119
networks . forEach ( network => {
118
120
networkSpaceCounts [ network ] = ( networkSpaceCounts [ network ] || 0 ) + 1 ;
You can’t perform that action at this time.
0 commit comments