Improve preloading #411
Merged
Merged
Conversation
Collaborator
Author
0668179 to
a00f114
Compare
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes in this pull request
Checklist
CHANGELOG.mdfor any breaking changes, enhancements, or bug fixes.ktlintin the main directory and fixed any issues.Greptile Summary
This PR improves preloading by limiting
IF_TRUEcampaign rules to the first matching experiment per group (rather than all matches), and adds fingerprint-based re-preload triggers that fire on device/subscription/configuration changes.ConfigLogic.getAllActiveTreatmentPaywallIdsis refactored to keep only the first matchingIF_TRUErule per campaign and skip the rest, whileALWAYSandNEVERrules remain unaffected; new tests cover the cross-behavior combinations.PaywallPreload.preloadAllPaywallsgains anAtomicReference-backed fingerprint with CAS dedup + rollback, andConfigManager.recheckPreloadIfNeededdispatchesPreloadIfEnabled(honoring the device-tier preload-enabled gate) when the fingerprint changes.Superwallregisters aComponentCallbacks2listener for locale/timezone/interface-style changes and callsrecheckPreloadIfNeededfrom subscription-status, customer-info, interface-style-override, and review-request change sites;DeviceHelper.preloadFingerprint()bundles all relevant fields into a stable string for comparison.Confidence Score: 4/5
Safe to merge with awareness of the open fingerprint-rollback-under-concurrent-load scenario and the remaining Superwall.instance path inside customerInfoFlow().
The four core improvements (first-match-only IF_TRUE preloading, AtomicReference CAS dedup with rollback, PreloadIfEnabled dispatch honouring the device-tier gate, and ComponentCallbacks2 re-trigger) all look correct for the non-concurrent steady-state path. The concurrent rollback scenario — where two callers race CAS in sequence and the second rollback restores an unpreloaded fingerprint — remains partially open, as does the customerInfoFlow() path through Superwall.instance in DeviceHelper. Both are carryovers from the prior review cycle and are mitigated but not eliminated by the new CAS logic.
PaywallPreload.kt (CAS rollback under concurrent callers) and DeviceHelper.kt (customerInfoFlow() still routes through Superwall.instance).
Important Files Changed
Sequence Diagram
sequenceDiagram participant SW as Superwall participant CM as ConfigManager participant PP as PaywallPreload participant DH as DeviceHelper participant CS as ConfigState.Actions Note over SW: Subscription / CustomerInfo / Config / Review change SW->>CM: recheckPreloadIfNeeded() CM->>CM: getConfig() or return CM->>CM: hasIfTrueRule? or return CM->>DH: preloadFingerprint() DH-->>CM: fingerprint "NEW" CM->>PP: lastFingerprint.get() → "OLD" (≠ "NEW") CM->>CS: immediate(PreloadIfEnabled) CS->>DH: computedShouldPreload(deviceTier)? alt preload disabled CS-->>CM: return (no-op) else preload enabled CS->>DH: preloadFingerprint() → "NEW" CS->>PP: preloadAllPaywalls(config, ctx, "NEW") PP->>PP: CAS lastFingerprint("OLD" → "NEW") alt task already running PP->>PP: rollback CAS("NEW" → "OLD") PP-->>CS: return (retry later) else no task running PP->>PP: launch preload coroutine PP->>PP: getAllActiveTreatmentPaywallIds() Note over PP: Only first matching IF_TRUE per campaign PP-->>CS: preload started end endPrompt To Fix All With AI
Reviews (3): Last reviewed commit: "Ensure recheck only preloads if enabled" | Re-trigger Greptile