@@ -120,17 +120,50 @@ async function getMemberData(ctx: IProcessStreamContext, login: string): Promise
120
120
} )
121
121
}
122
122
123
+ async function getOrganizationData ( ctx : IProcessStreamContext , company : string ) : Promise < any > {
124
+ if ( company === '' || company === null || company === undefined ) {
125
+ return null
126
+ }
127
+
128
+ const cache = ctx . globalCache
129
+ const prefix = ( x : string ) => `github-org:${ x } `
130
+
131
+ const existing = await cache . get ( prefix ( company ) )
132
+ if ( existing ) {
133
+ if ( existing === 'null' ) {
134
+ return null
135
+ }
136
+
137
+ return JSON . parse ( existing )
138
+ }
139
+
140
+ const token = await getGithubToken ( ctx )
141
+ const fromAPI = await getOrganization ( company , token , getTokenRotator ( ctx ) , {
142
+ concurrentRequestLimiter : getConcurrentRequestLimiter ( ctx ) ,
143
+ integrationId : ctx . integration . id ,
144
+ } )
145
+
146
+ if ( fromAPI ) {
147
+ await cache . set ( prefix ( company ) , JSON . stringify ( fromAPI ) , 24 * 60 * 60 )
148
+ return fromAPI
149
+ }
150
+
151
+ await cache . set ( prefix ( company ) , 'null' , 24 * 60 * 60 )
152
+ return null
153
+ }
154
+
123
155
async function getMemberEmail ( ctx : IProcessStreamContext , login : string ) : Promise < string > {
124
156
if ( IS_TEST_ENV ) {
125
157
return ''
126
158
}
127
159
128
- // here we use cache for tenantId-integrationType
160
+ // here we use global cache - it is shared between all integrations
129
161
// So in LFX case different integration will have access to the same cache
130
162
// But this is fine
131
- const cache = ctx . cache
163
+ const cache = ctx . globalCache
164
+ const prefix = ( x : string ) => `github-login:${ x } `
132
165
133
- const existing = await cache . get ( login )
166
+ const existing = await cache . get ( prefix ( login ) )
134
167
if ( existing ) {
135
168
if ( existing === 'null' ) {
136
169
return ''
@@ -142,11 +175,11 @@ async function getMemberEmail(ctx: IProcessStreamContext, login: string): Promis
142
175
const member = await getMemberData ( ctx , login )
143
176
const email = ( member && member . email ? member . email : '' ) . trim ( )
144
177
if ( email && email . length > 0 ) {
145
- await cache . set ( login , email , 60 * 60 )
178
+ await cache . set ( prefix ( login ) , email , 60 * 60 )
146
179
return email
147
180
}
148
181
149
- await cache . set ( login , 'null' , 60 * 60 )
182
+ await cache . set ( prefix ( login ) , 'null' , 60 * 60 )
150
183
return ''
151
184
}
152
185
@@ -179,12 +212,7 @@ export const prepareMember = async (
179
212
orgs = [ { name : 'crowd.dev' } ]
180
213
} else {
181
214
const company = memberFromApi . company . replace ( '@' , '' ) . trim ( )
182
- const token = await getGithubToken ( ctx )
183
- const fromAPI = await getOrganization ( company , token , getTokenRotator ( ctx ) , {
184
- concurrentRequestLimiter : getConcurrentRequestLimiter ( ctx ) ,
185
- integrationId : ctx . integration . id ,
186
- } )
187
-
215
+ const fromAPI = await getOrganizationData ( ctx , company )
188
216
orgs = fromAPI
189
217
}
190
218
}
0 commit comments