Skip to content

Commit

Permalink
Do not base cache expiry on subscription expiry date (#1150)
Browse files Browse the repository at this point in the history
Please review the release process for BrowserServicesKit
[here](https://app.asana.com/0/1200194497630846/1200837094583426).

**Required**:

Task/Issue URL:
https://app.asana.com/0/1201037661562251/1209111606760738/f
iOS PR: /will follow in internal build - not impacted/
macOS PR: duckduckgo/macos-browser#3714
What kind of version bump will this require?: Hotfix

**Optional**:

CC: @federicocappelli 

**Description**:
In specific conditions we may cause an endless loop of remote API calls
to fetch the subscription.

**Steps to test this PR**:
(macOS only)
1. Have an expired subscription in the app
2. Ensure that `isLaunchedROW` or `isLaunchedROWOverride` feature flag
is enabled in privacy config.
3. Open Settings tab
4. From sidebar open "Privacy Pro"
5. Check network calls: only a single remote call should be made to GET
subscription from subscriptions BE endpoint

<!--
Before submitting a PR, please ensure you have tested the combinations
you expect the reviewer to test, then delete configurations you *know*
do not need explicit testing.

Using a simulator where a physical device is unavailable is acceptable.
-->

**OS Testing**:
* [ ] macOS

---
###### Internal references:
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
  • Loading branch information
miasma13 authored Jan 9, 2025
1 parent e8f94cf commit 2eddeb9
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions Sources/Subscription/API/SubscriptionEndpointService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ public struct DefaultSubscriptionEndpointService: SubscriptionEndpointService {

let cachedSubscription: Subscription? = subscriptionCache.get()
if subscription != cachedSubscription {
let defaultExpiryDate = Date().addingTimeInterval(subscriptionCache.settings.defaultExpirationInterval)
let expiryDate = min(defaultExpiryDate, subscription.expiresOrRenewsAt)

subscriptionCache.set(subscription, expires: expiryDate)
subscriptionCache.set(subscription)
NotificationCenter.default.post(name: .subscriptionDidChange, object: self, userInfo: [UserDefaultsCacheKey.subscription: subscription])
}
}
Expand Down

0 comments on commit 2eddeb9

Please sign in to comment.