Skip to content

StoreKit1Wrapper: process transactions in a background thread#2115

Merged
NachoSoto merged 4 commits into
mainfrom
storekit-1-wrapper-process-bg
Dec 7, 2022
Merged

StoreKit1Wrapper: process transactions in a background thread#2115
NachoSoto merged 4 commits into
mainfrom
storekit-1-wrapper-process-bg

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Dec 5, 2022

Copy link
Copy Markdown
Contributor

Fixes #2107 and SDKONCALL-180. That's a rare issue where a user ends up with thousands of transactions.
That exposed the fact that we're processing all of these transactions on the main thread. This fixes that.

See #2107. That's a rare issue where a user ends up with thousands of transactions.
That exposed the fact that we're processing all of these transactions on the main thread. This fixes that.
@NachoSoto NachoSoto added the perf label Dec 5, 2022
@NachoSoto NachoSoto requested a review from a team December 5, 2022 15:18
private let operationDispatcher: OperationDispatcher

init(paymentQueue: SKPaymentQueue) {
init(paymentQueue: SKPaymentQueue, operationDispatcher: OperationDispatcher) {

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.

I need to pass the same one down from Purchases here.

Comment thread Tests/UnitTests/Purchasing/StoreKit1WrapperTests.swift Outdated
Comment thread Tests/UnitTests/Purchasing/StoreKit1WrapperTests.swift Outdated
Comment thread Tests/UnitTests/Purchasing/StoreKit1WrapperTests.swift Outdated
@NachoSoto NachoSoto force-pushed the storekit-1-wrapper-process-bg branch from 8d1cce5 to da0b5b8 Compare December 5, 2022 20:02
NachoSoto added a commit that referenced this pull request Dec 5, 2022
…actions

See #2107. We still don't know what caused that, but it leads to degraded performance (mildly reduced by #2115).
To advice of that, in case users are wondering why the app might potentially take excessive CPU usage, I added this warning.

@aboedo aboedo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

makes sense, good catch

@NachoSoto NachoSoto merged commit d389d7e into main Dec 7, 2022
@NachoSoto NachoSoto deleted the storekit-1-wrapper-process-bg branch December 7, 2022 22:37
NachoSoto added a commit that referenced this pull request Dec 13, 2022
…actions

See #2107. We still don't know what caused that, but it leads to degraded performance (mildly reduced by #2115).
To advice of that, in case users are wondering why the app might potentially take excessive CPU usage, I added this warning.
NachoSoto added a commit that referenced this pull request Dec 15, 2022
…ottle errors (#2146)

Fixes #2116.

Depends on #2134, #2144, #2145.

We've known that, especially for sandbox accounts with lots of
purchases, the SDK can get flooded with a lot of transactions to process
at once.
I've been making some improvements for this (like #2115).

Another consequence of this behavior, is that we can end up failing due
to `StoreKit` throttling us (see #2116):

> 2022-12-03 12:31:58.670892+0100 app[673:61074]
<SKReceiptRefreshRequest: 0x283edc860>: Finished refreshing receipt with
error: Error Domain=ASDErrorDomain Code=603 "Request throttled"
UserInfo={NSLocalizedFailureReason=Unified receipt is valid and current,
NSLocalizedDescription=Request throttled, AMSServerErrorCode=0}

This change avoids that by skipping the refresh if less than 2 seconds
have elapsed. I chose 2 to make this a low-ish risk change, with a huge
benefit for multiple semi-concurrent requests coming from a big
transaction queue.
NachoSoto added a commit that referenced this pull request Dec 20, 2022
…actions (#2117)

See #2107. We still don't know what caused that, but it leads to
degraded performance (mildly reduced by #2115). To advice of that, in
case users are wondering why the app might potentially take excessive
CPU usage, I added this warning.
@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.

Processing under the main thread hangs the UI

3 participants