Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent null value changes to observe listeners #352

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion LaunchDarkly/LaunchDarkly/LDClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,27 @@ public class LDClient {
let cachedData = self.flagCache.getCachedData(cacheKey: self.context.contextHash())
let cachedContextFlags = cachedData.items ?? [:]
let oldItems = flagStore.storedItems.featureFlags

// Here we prime the store with the last known values from the
// cache.
//
// Once the flag sync. process finishes, the new payload is
// compared to this, and if they are different, change listeners
// will be notified; otherwise, they aren't.
//
// This is problematic since the flag values really did change. So
// we should trigger the change listener when we set these cache
// values.
//
// However, if there are no cached values, we don't want to inform
// customers that we set their store to nothing. In that case, we
// will not trigger the change listener and instead relay on the
// payload comparsion to do that when the request has completed.
flagStore.replaceStore(newStoredItems: cachedContextFlags)
flagChangeNotifier.notifyObservers(oldFlags: oldItems, newFlags: flagStore.storedItems.featureFlags)
if !cachedContextFlags.featureFlags.isEmpty {
flagChangeNotifier.notifyObservers(oldFlags: oldItems, newFlags: flagStore.storedItems.featureFlags)
}

self.service.context = self.context
self.service.resetFlagResponseCache(etag: cachedData.etag)
flagSynchronizer = serviceFactory.makeFlagSynchronizer(streamingMode: ConnectionInformation.effectiveStreamingMode(config: config, ldClient: self),
Expand Down