Skip to content

Conversation

joshdholtz
Copy link
Member

Motivation

Refetch current offerings (no cache) when preferred locale is set

Description

Use a rate limiter when attempting to fetch current offerings when setting preferred locale (2 times per minute)

@joshdholtz joshdholtz requested review from a team August 29, 2025 20:15
@joshdholtz joshdholtz force-pushed the paywall-preferred-locale-refetch-offerings branch from 1e1d72c to c8ff9b7 Compare August 29, 2025 20:20
Copy link

emerge-tools bot commented Aug 29, 2025

📸 Snapshot Test

2 modified, 691 unchanged

Name Added Removed Modified Renamed Unchanged Errored Approval
RevenueCat
com.revenuecat.PaywallsTester
0 0 1 0 230 0 ✅ Approved
RevenueCat
com.revenuecat.PaywallsTester.mac-catalyst-scaled-to-match-ipad
0 0 0 0 231 0 N/A
RevenueCat
com.revenuecat.PaywallsTester.mac-catalyst-optimized-for-mac
0 0 1 0 230 0 ✅ Approved

🛸 Powered by Emerge Tools

Copy link
Member

@ajpallares ajpallares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition! This is something we discussed about whether or not to add precisely to avoid too many requests. But the rate limiter does solve it 👌
Before approving though, I have a small suggestion.

Comment on lines +1936 to +1941
if self.overridePreferredUILocaleRateLimiter.shouldProceed() {
// Refetches new offerings with preferred locale
self.getOfferings(fetchPolicy: .default, fetchCurrent: true) { _, _ in
// No-op
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could trigger the getOfferings only when

self.systemInfo.preferredLocaleOverride != locale

It's the most basic comparison, but at least it guards against developers setting to the already-set preferred locale.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather bump that responsibility to the networking layer, but I see that we are using an ephemeral session with no cache. And our e-tag cache isn't well suited for this… is there a reason we can't inject a flag to a request to use a non ephemeral session and set the cache policy to something really short like a minute?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't inject a flag to a request to use a non ephemeral session and set the cache policy to something really short like a minute?

This is a question 🤔 I'm do not remember off the top of my head why we use the session and caching that we use. I used to know at one point but probably should understand again 🤷‍♂️

I'd rather bump that responsibility to the networking layer

I'll leave it here for now since it short circuits it right at the start without touching any other layers and so its explicit that we aren't doing any extra networking calls to our API

@joshdholtz joshdholtz merged commit a2cf396 into main Sep 3, 2025
12 checks passed
@joshdholtz joshdholtz deleted the paywall-preferred-locale-refetch-offerings branch September 3, 2025 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants