Skip to content

Commit

Permalink
fix: Providing an OfflineHandler causes the SDK to bypass live flag l…
Browse files Browse the repository at this point in the history
…ookups
  • Loading branch information
khvn26 committed Jul 22, 2024
1 parent 364948d commit 844bdc1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Flagsmith.FlagsmithClient/FlagsmithClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ public FlagsmithClient(
this.Retries = retries;
this.RequestTimeout = requestTimeout;
this._httpClient = httpClient ?? new HttpClient();
this.CacheConfig = cacheConfig ?? new CacheConfig(false);
this.CacheConfig = cacheConfig ?? new CacheConfig(false);
this.OfflineMode = offlineMode;
this._offlineHandler = offlineHandler;
_engine = new Engine();

_engine = new Engine();

if (OfflineMode && _offlineHandler is null)
{
throw new Exception("ValueError: offlineHandler must be provided to use offline mode.");
Expand Down Expand Up @@ -203,7 +203,7 @@ public async Task<IFlags> GetEnvironmentFlags()

private async Task<IFlags> GetFeatureFlagsFromCorrectSource()
{
return Environment != null ? GetFeatureFlagsFromDocument() : await GetFeatureFlagsFromApi().ConfigureAwait(false);
return OfflineMode ? GetFeatureFlagsFromDocument() : await GetFeatureFlagsFromApi().ConfigureAwait(false);
}

/// <summary>
Expand All @@ -226,8 +226,8 @@ public async Task<IFlags> GetIdentityFlags(string identifier, List<ITrait>? trai
var flagListCache = GetFlagListCacheByIdentity(identityWrapper);

return flagListCache.GetLatestFlags(GetIdentityFlagsFromCorrectSource);
}

}

if (this.OfflineMode)
return this.GetIdentityFlagsFromDocument(identifier, traits ?? null);

Expand Down Expand Up @@ -319,7 +319,7 @@ private async Task GetAndUpdateEnvironmentFromApi()
try
{
var json = await GetJson(HttpMethod.Get, ApiUrl + "environment-document/").ConfigureAwait(false);
Environment = JsonConvert.DeserializeObject<EnvironmentModel>(json);
Environment = JsonConvert.DeserializeObject<EnvironmentModel>(json);
IdentitiesWithOverridesByIdentifier = Environment?.IdentityOverrides != null ? Environment.IdentityOverrides.ToDictionary(identity => identity.Identifier) : new Dictionary<string, IdentityModel>();
Logger?.LogInformation("Local Environment updated: " + json);
}
Expand All @@ -339,7 +339,7 @@ private async Task<IFlags> GetFeatureFlagsFromApi()
return Flags.FromApiFlag(_analyticsProcessor, DefaultFlagHandler, flags);
}
catch (FlagsmithAPIError e)
{
{
if (Environment != null)
{
return this.GetFeatureFlagsFromDocument();
Expand Down Expand Up @@ -372,7 +372,7 @@ private async Task<IFlags> GetIdentityFlagsFromApi(string identity, List<ITrait>
return Flags.FromApiFlag(_analyticsProcessor, DefaultFlagHandler, flags);
}
catch (FlagsmithAPIError e)
{
{
if (Environment != null)
{
return this.GetIdentityFlagsFromDocument(identity, traits);
Expand Down Expand Up @@ -406,8 +406,8 @@ private IFlags GetIdentityFlagsFromDocument(string identifier, List<ITrait>? tra
};
}
return Flags.FromFeatureStateModel(_analyticsProcessor, DefaultFlagHandler, _engine.GetIdentityFeatureStates(Environment, identity), identity.CompositeKey);
}

}

public Dictionary<string, int> aggregatedAnalytics => _analyticsProcessor != null ? _analyticsProcessor.GetAggregatedAnalytics() : new Dictionary<string, int>();

~FlagsmithClient() => _pollingManager?.StopPoll();
Expand Down

0 comments on commit 844bdc1

Please sign in to comment.