Skip to content

Created CachingTrialOrIntroPriceEligibilityChecker#2007

Merged
NachoSoto merged 8 commits into
mainfrom
trial-checker-cache-2
Jan 12, 2023
Merged

Created CachingTrialOrIntroPriceEligibilityChecker#2007
NachoSoto merged 8 commits into
mainfrom
trial-checker-cache-2

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Oct 27, 2022

Copy link
Copy Markdown
Contributor

Fixes CSDK-493.

This will help a little bit with the SK2 performance issues computing eligibility (#1893).

@NachoSoto NachoSoto added the perf label Oct 27, 2022
@NachoSoto NachoSoto requested a review from a team October 27, 2022 22:58
@NachoSoto NachoSoto force-pushed the trial-checker-cache branch from 58b80b8 to 45990bb Compare November 2, 2022 15:54

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

Comment thread Sources/FoundationExtensions/AsyncExtensions.swift Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, this seems unused other than in tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's actually public API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But that's the completion version, not this one with async right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oooh good catch! I moved this to just the test file.

@NachoSoto NachoSoto force-pushed the trial-checker-cache-2 branch from 0fc4943 to 3d7b147 Compare November 3, 2022 21:34
NachoSoto added a commit that referenced this pull request Nov 4, 2022
…ons`

This changes the default back to `StoreKit 1`. We decided to do this for the following reasons:
- Purchasing with `PromotionalOffer`s does not work with StoreKit 2 due to an Apple bug (see #2020 (comment))
- `checkTrialOrIntroDiscountEligibility` is significantly slower with StoreKit 2 (#1893). We're adding optimizations to help with that (#2007), but the underlying logic will still be slow.
- A rare race-condition where `StoreKit 2` does not have transactions after a purchase ([TRIAGE-82]). We have some workarounds (#1945), but it's still being investigated.

_ Note: This effectively reverts 0ee540a. That commit made it easier to only change the default in one place which is why this PR is basically just one line._
NachoSoto added a commit that referenced this pull request Nov 4, 2022
…ons` (#2022)

This changes the default back to `StoreKit 1`. We decided to do this for
the following reasons:
- Purchasing with `PromotionalOffer`s does not work with StoreKit 2 due
to an Apple bug (see
#2020 (comment))
- `checkTrialOrIntroDiscountEligibility` is significantly slower with
`StoreKit 2` (#1893). We're adding optimizations to help with that
(#2007), but the underlying logic will still be slow.
- A rare race-condition where `StoreKit 2` does not have transactions
after a purchase ([TRIAGE-82]). We have some workarounds (#1945), but
it's still being investigated.

_Note: This effectively reverts 0ee540a. That commit made it easier to
only change the default in one place which is why this PR is basically
just one line._

[TRIAGE-82]:
https://revenuecats.atlassian.net/browse/TRIAGE-82?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Base automatically changed from trial-checker-cache to main November 7, 2022 20:40
@NachoSoto NachoSoto force-pushed the trial-checker-cache-2 branch from d45d8bf to b08f3e4 Compare November 7, 2022 20:40
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Oh wait we need to invalidate this cache when we make purchases or they expire of course 🤦🏻‍♂️
Caching and off-by-one errors, the 3 hardest problems in computer science.

@NachoSoto NachoSoto added invalid and removed invalid labels Nov 7, 2022
@NachoSoto NachoSoto marked this pull request as draft November 7, 2022 21:17
@NachoSoto NachoSoto requested a review from a team November 7, 2022 21:17
@NachoSoto NachoSoto force-pushed the trial-checker-cache-2 branch from b08f3e4 to 7eee829 Compare November 9, 2022 14:41
@NachoSoto NachoSoto changed the base branch from main to notification-subscriptions-changed November 15, 2022 18:18
@NachoSoto NachoSoto force-pushed the trial-checker-cache-2 branch from 7eee829 to 40e74fd Compare November 15, 2022 18:18
@NachoSoto NachoSoto marked this pull request as ready for review November 15, 2022 18:56
@NachoSoto

NachoSoto commented Nov 15, 2022

Copy link
Copy Markdown
Contributor Author

This is ready for review again @RevenueCat/coresdk, I'm now clearing the cache when subscriptions change (using #2057), which should fix integration tests.

@NachoSoto NachoSoto force-pushed the notification-subscriptions-changed branch from 3eddf69 to 2f68cc7 Compare November 15, 2022 19:14
@NachoSoto NachoSoto force-pushed the trial-checker-cache-2 branch 2 times, most recently from e348a00 to f632a4a Compare November 15, 2022 19:16
@NachoSoto NachoSoto requested a review from tonidero November 15, 2022 19:20
Comment thread Sources/Purchasing/CachingTrialOrIntroPriceEligibilityChecker.swift Outdated
@NachoSoto NachoSoto force-pushed the notification-subscriptions-changed branch from 2f68cc7 to eca596c Compare November 23, 2022 18:21
@NachoSoto NachoSoto force-pushed the trial-checker-cache-2 branch from f632a4a to 5409752 Compare November 23, 2022 18:24
@NachoSoto NachoSoto force-pushed the notification-subscriptions-changed branch from a9938b8 to 376e162 Compare December 20, 2022 22:39
@NachoSoto NachoSoto force-pushed the trial-checker-cache-2 branch from 070785d to 4eeacdf Compare December 20, 2022 22:40
@NachoSoto NachoSoto force-pushed the trial-checker-cache-2 branch from 4eeacdf to cb25a28 Compare January 5, 2023 22:51
@NachoSoto NachoSoto removed the blocked label Jan 5, 2023
@NachoSoto NachoSoto changed the base branch from notification-subscriptions-changed to main January 5, 2023 22:52
private extension Purchases {

func handleCustomerInfoChanged(_ customerInfo: CustomerInfo) {
self.trialOrIntroPriceEligibilityChecker.clearCache()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@aboedo per our discussion, this ordering now ensures there are no race conditions.

@NachoSoto NachoSoto requested a review from aboedo January 5, 2023 22:55
@NachoSoto

NachoSoto commented Jan 5, 2023

Copy link
Copy Markdown
Contributor Author

Updated this to clear caches using the existing CustomerInfoManager observation mechanism /cc @aboedo

@NachoSoto NachoSoto merged commit f3a6d20 into main Jan 12, 2023
@NachoSoto NachoSoto deleted the trial-checker-cache-2 branch January 12, 2023 18:20
NachoSoto pushed a commit that referenced this pull request Jan 17, 2023
**This is an automatic release.**

### New Features
* Added new `ReceiptParser.fetchAndParseLocalReceipt` (#2204) via
NachoSoto (@NachoSoto)
* `PurchasesReceiptParser`: added API to parse receipts from `base64`
string (#2200) via NachoSoto (@NachoSoto)
### Bugfixes
* `CustomerInfo`: support parsing schema version 2 to restore SDK `v3.x`
compatibility (#2213) via NachoSoto (@NachoSoto)
### Other Changes
* `JSONDecoder`: added decoding type when logging
`DecodingError.keyNotFound` (#2212) via NachoSoto (@NachoSoto)
* Added `ReceiptParserTests` (#2203) via NachoSoto (@NachoSoto)
* Deploy `PurchaseTester` for `macOS` (#2011) via NachoSoto (@NachoSoto)
* `ReceiptFetcher`: refactored implementation to log error when failing
to fetch receipt (#2202) via NachoSoto (@NachoSoto)
* `PostReceiptDataOperation`: replaced receipt `base64` with `hash` for
cache key (#2199) via NachoSoto (@NachoSoto)
* `PurchaseTester`: small refactor to simplify `Date` formatting (#2210)
via NachoSoto (@NachoSoto)
* `PurchasesReceiptParser`: improved documentation to reference
`default` (#2197) via NachoSoto (@NachoSoto)
* Created `CachingTrialOrIntroPriceEligibilityChecker` (#2007) via
NachoSoto (@NachoSoto)
* Update Gemfile.lock (#2205) via Cesar de la Vega (@vegaro)
* remove stalebot in favor of SLAs in Zendesk (#2196) via Andy Boedo
(@aboedo)
* Update fastlane-plugin-revenuecat_internal to latest version (#2194)
via Cesar de la Vega (@vegaro)
NachoSoto added a commit that referenced this pull request Jul 24, 2023
This will help provide a better experience when launching paywalls, as hopefully we will have already computed intro eligibility by then.
This is even better than when using `StoreKit` paywalls.

Note that thanks to `CachingTrialOrIntroPriceEligibilityChecker` (#2007) this is cached automatically, and also it handles multiple requests with the same or different product identifiers.
@vegaro vegaro added pr:other and removed pr:perf labels Sep 17, 2024
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.

4 participants