@@ -42,23 +42,57 @@ export default class ConfigurationRequestor {
42
42
format : configResponse . format ,
43
43
} ) ;
44
44
45
- // TODO: different polling intervals for bandit parameters
46
- const banditResponse = await this . httpClient . getBanditParameters ( ) ;
47
- if ( banditResponse ?. bandits ) {
48
- if ( ! this . banditModelConfigurationStore ) {
49
- throw new Error ( 'Bandit parameters fetched but no bandit configuration store provided' ) ;
50
- }
45
+ if ( this . requiresBanditModelConfigurationStoreUpdate ( configResponse . banditReferences ) ) {
46
+ const banditResponse = await this . httpClient . getBanditParameters ( ) ;
47
+ if ( banditResponse ?. bandits ) {
48
+ if ( ! this . banditModelConfigurationStore ) {
49
+ throw new Error ( 'Bandit parameters fetched but no bandit configuration store provided' ) ;
50
+ }
51
51
52
- await hydrateConfigurationStore ( this . banditModelConfigurationStore , {
53
- entries : banditResponse . bandits ,
54
- environment : configResponse . environment ,
55
- createdAt : configResponse . createdAt ,
56
- format : configResponse . format ,
57
- } ) ;
52
+ await hydrateConfigurationStore ( this . banditModelConfigurationStore , {
53
+ entries : banditResponse . bandits ,
54
+ environment : configResponse . environment ,
55
+ createdAt : configResponse . createdAt ,
56
+ format : configResponse . format , } ) ;
57
+ }
58
58
}
59
59
}
60
60
}
61
61
62
+ private getLoadedBanditModelVersions (
63
+ banditModelConfigurationStore : IConfigurationStore < BanditParameters > | null ,
64
+ ) {
65
+ if ( banditModelConfigurationStore === null ) {
66
+ return [ ] ;
67
+ }
68
+ return Object . values ( banditModelConfigurationStore . entries ( ) ) . map (
69
+ ( banditParam : BanditParameters ) => banditParam . modelVersion ,
70
+ ) ;
71
+ }
72
+
73
+ private requiresBanditModelConfigurationStoreUpdate (
74
+ banditReferences : Record < string , BanditReference > ,
75
+ ) : boolean {
76
+ if ( ! this . banditModelConfigurationStore ) {
77
+ throw new Error ( 'Bandit parameters fetched but no bandit configuration store provided' ) ;
78
+ }
79
+ const referencedModelVersions = Object . values ( banditReferences ) . map (
80
+ ( banditReference : BanditReference ) => banditReference . modelVersion
81
+ ) ;
82
+
83
+ const banditModelVersionsInStore = this . getLoadedBanditModelVersions (
84
+ this . banditModelConfigurationStore ,
85
+ ) ;
86
+
87
+ referencedModelVersions . forEach ( ( modelVersion ) => {
88
+ if ( ! banditModelVersionsInStore . includes ( modelVersion ) ) {
89
+ return false ;
90
+ }
91
+ } ) ;
92
+
93
+ return true ;
94
+ }
95
+
62
96
private indexBanditVariationsByFlagKey (
63
97
banditVariationsByBanditKey : Record < string , BanditVariation [ ] > ,
64
98
) : Record < string , BanditVariation [ ] > {
0 commit comments