11import { CacheClient } from "../app" ;
22import { ILogger } from "../logging" ;
3- import { AddMemberResponse , CopilotAddResponse , GitHubId , GitHubTeamId , InstalledClient , OrgConfigResponse , OrgInvite , OrgRoles , RemoveMemberResponse , Response } from "./gitHubTypes" ;
4- import { OrgConfig } from "./orgConfig" ;
3+ import { AddMemberResponse , CopilotAddResponse , GitHubTeamId , InstalledClient , OrgConfigResponse , OrgInvite , OrgRoles , RemoveMemberResponse , Response } from "./gitHubTypes" ;
54
65export class GitHubClientCache implements InstalledClient {
76 client : InstalledClient ;
@@ -13,6 +12,7 @@ export class GitHubClientCache implements InstalledClient {
1312 this . cacheClient = cacheClient ;
1413 this . logger = logger ;
1514 }
15+
1616 AddTeamsToCopilotSubscription ( teamNames : string [ ] ) : Response < CopilotAddResponse [ ] > {
1717 return this . client . AddTeamsToCopilotSubscription ( teamNames ) ;
1818 }
@@ -46,20 +46,17 @@ export class GitHubClientCache implements InstalledClient {
4646 }
4747
4848 async IsUserMember ( id : string ) : Response < boolean > {
49- const cacheKey = `github-member:${ id } -${ this . GetCurrentOrgName ( ) } ` ;
49+ const cacheKey = `github-member-1 :${ id } -${ this . GetCurrentOrgName ( ) } ` ;
5050
5151 const result = await this . cacheClient . get ( cacheKey ) ;
5252
5353 if ( result ) {
54- this . logger . ReportEvent ( {
55- Name :"CacheHit" ,
56- properties : {
57- "Data" : id ,
58- "Operation" : "IsUserMember" ,
59- "Group" : "GitHub" ,
60- "Value" : result
61- }
62- } )
54+ this . ReportCacheHit ( {
55+ cacheKey : cacheKey ,
56+ operation : "IsUserMember" ,
57+ value : result ,
58+ user : id
59+ } ) ;
6360
6461 return {
6562 successful : true ,
@@ -111,16 +108,13 @@ export class GitHubClientCache implements InstalledClient {
111108
112109 const result = await this . cacheClient . get ( cacheKey ) ;
113110
114- if ( result ) {
115- this . logger . ReportEvent ( {
116- Name :"CacheHit" ,
117- properties : {
118- "Data" : gitHubId ,
119- "Operation" : "DoesUserExist" ,
120- "Group" : "GitHub" ,
121- "Value" : result
122- }
123- } )
111+ if ( result ) {
112+ this . ReportCacheHit ( {
113+ operation : "DoesUserExist" ,
114+ user : gitHubId ,
115+ value : result ,
116+ cacheKey : cacheKey
117+ } ) ;
124118
125119 return JSON . parse ( result ) ;
126120 }
@@ -167,4 +161,27 @@ export class GitHubClientCache implements InstalledClient {
167161 GetConfigurationForInstallation ( ) : OrgConfigResponse {
168162 return this . client . GetConfigurationForInstallation ( ) ;
169163 }
164+
165+ private ReportCacheHit ( props : { operation : string , user ?: string , team ?:string , value : string , cacheKey :string } ) {
166+ const properties :any = {
167+ "Group" : "GitHub" ,
168+ "Operation" : props . operation ,
169+ "Org" : this . GetCurrentOrgName ( ) ,
170+ "Value" : props . value ,
171+ "CacheKey" : props . cacheKey
172+ } ;
173+
174+ if ( props . user ) {
175+ properties [ "User" ] = props . user ;
176+ }
177+
178+ if ( props . team ) {
179+ properties [ "Team" ] = props . team ;
180+ }
181+
182+ this . logger . ReportEvent ( {
183+ Name :"CacheHit" ,
184+ properties : properties
185+ } ) ;
186+ }
170187}
0 commit comments