@@ -527,7 +527,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
527527 labelFilter : selector . labelFilter
528528 } ;
529529
530- // If cdn is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
530+ // If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
531531 if ( this . #isCdnUsed) {
532532 listOptions = {
533533 ...listOptions ,
@@ -631,18 +631,19 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
631631 /**
632632 * Updates etag of watched settings from loaded data. If a watched setting is not covered by any selector, a request will be sent to retrieve it.
633633 */
634- async #updateWatchedKeyValuesEtag( existingSettings : ConfigurationSetting [ ] ) : Promise < void > {
634+ async #updateWatchedKeyValuesEtag( loadedSettings : ConfigurationSetting [ ] ) : Promise < void > {
635635 for ( const sentinel of this . #sentinels) {
636- const matchedSetting = existingSettings . find ( s => s . key === sentinel . key && s . label === sentinel . label ) ;
637- if ( matchedSetting ) {
638- sentinel . etag = matchedSetting . etag ;
636+ const loaded = loadedSettings . find ( s => s . key === sentinel . key && s . label === sentinel . label ) ;
637+ if ( loaded ) {
638+ sentinel . etag = loaded . etag ;
639639 } else {
640640 // Send a request to retrieve watched key-value since it may be either not loaded or loaded with a different selector
641- // If cdn is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
642- const getOptions = this . #isCdnUsed ?
643- { requestOptions : { customHeaders : { [ ETAG_LOOKUP_HEADER ] : this . #kvSelectorCollection. cdnCacheBreakString ?? "" } } } :
644- { } ;
645- const response = await this . #getConfigurationSetting( sentinel , { ...getOptions , onlyIfChanged : false } ) ; // always send non-conditional request
641+ // If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
642+ let getOptions : GetConfigurationSettingOptions = { } ;
643+ if ( this . #isCdnUsed) {
644+ getOptions = { requestOptions : { customHeaders : { [ ETAG_LOOKUP_HEADER ] : this . #kvSelectorCollection. cdnCacheBreakString ?? "" } } } ;
645+ }
646+ const response = await this . #getConfigurationSetting( sentinel , getOptions ) ;
646647 sentinel . etag = response ?. etag ;
647648 }
648649 }
@@ -695,12 +696,22 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
695696 if ( this . #watchAll) {
696697 needRefresh = await this . #checkConfigurationSettingsChange( this . #kvSelectorCollection) ;
697698 }
699+ // if watchAll is true, there should be no sentinels
698700 for ( const sentinel of this . #sentinels. values ( ) ) {
699- // If cdn is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
700- const getOptions = this . #isCdnUsed ?
701- { requestOptions : { customHeaders : { [ ETAG_LOOKUP_HEADER ] : this . #kvSelectorCollection. cdnCacheBreakString ?? "" } } } :
702- { } ;
703- const response = await this . #getConfigurationSetting( sentinel , { ...getOptions , onlyIfChanged : ! this . #isCdnUsed } ) ; // if CDN is used, do not send conditional request
701+ // If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
702+ let getOptions : GetConfigurationSettingOptions = { } ;
703+ if ( this . #isCdnUsed) {
704+ // If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
705+ getOptions = {
706+ requestOptions : { customHeaders : { [ ETAG_LOOKUP_HEADER ] : this . #kvSelectorCollection. cdnCacheBreakString ?? "" } } ,
707+ } ;
708+ } else {
709+ // if CDN is not used, send conditional request
710+ getOptions = {
711+ onlyIfChanged : true
712+ } ;
713+ }
714+ const response = await this . #getConfigurationSetting( sentinel , getOptions ) ;
704715
705716 if ( ( response ?. statusCode === 200 && sentinel . etag !== response ?. etag ) ||
706717 ( response === undefined && sentinel . etag !== undefined ) // deleted
@@ -756,13 +767,17 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
756767 } ;
757768
758769 if ( this . #isCdnUsed) {
759- // If cdn is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
770+ // If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
760771 listOptions = {
761772 ...listOptions ,
762- requestOptions : { customHeaders : { [ ETAG_LOOKUP_HEADER ] : selectorCollection . cdnCacheBreakString ?? "" } } } ;
773+ requestOptions : { customHeaders : { [ ETAG_LOOKUP_HEADER ] : selectorCollection . cdnCacheBreakString ?? "" } }
774+ } ;
763775 } else {
764- // send conditional request if cdn is not used
765- listOptions = { ...listOptions , pageEtags : selector . pageEtags } ;
776+ // if CDN is not used, add page etags to the listOptions to send conditional request
777+ listOptions = {
778+ ...listOptions ,
779+ pageEtags : selector . pageEtags
780+ } ;
766781 }
767782
768783 const pageIterator = listConfigurationSettingsWithTrace (
0 commit comments