-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds callback cache identity #358
Conversation
@get:Synchronized @set:Synchronized | ||
@Volatile var createAliasCallbacks = mutableMapOf<CallbackCacheKey, MutableList<CreateAliasCallback>>() | ||
|
||
@get:Synchronized @set:Synchronized | ||
@Volatile var identifyCallbacks = mutableMapOf<CallbackCacheKey, MutableList<IdentifyCallback>>() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's fine for now, but we really should try to make this a common thing, which we can reuse easily. Perhaps at the HTTPClient level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thoughts I had
* adds callback cache to identity and createAlias * add log * use debuglog instead of Log * adds a delay # Conflicts: # common/src/main/java/com/revenuecat/purchases/common/Backend.kt # common/src/test/java/com/revenuecat/purchases/common/BackendTest.kt # strings/src/main/java/com/revenuecat/purchases/strings/NetworkStrings.kt
@@ -280,7 +291,11 @@ class Backend( | |||
onSuccessHandler: () -> Unit, | |||
onErrorHandler: (PurchasesError) -> Unit | |||
) { | |||
enqueue(object : Dispatcher.AsyncCall() { | |||
val cacheKey = listOfNotNull( | |||
appUserID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like tests only check that we don't repeat the call if both are the same. maybe we can add a test to confirm that if EITHER parameter has changed, we WILL repeat the call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that's a good catch. Want me to write it or you take care of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can!
We are getting some customers calling alias or identify too often. Sometimes with the same parameters.
Something I have noticed while trying to replicate the issue with this code:
Is that most of the times the code will enter in the
if
clause. The reason is that we only update the appUserID when the API call has come back with a result, so the check would most of the times evaluate to the same.In this PR, I have added the same caching mechanism we currently have for other API calls. It prevents the same calls being executed at the same time with the same parameters. This should prevent apps from hitting our servers with
/alias
and/identify
calls that look the same too often.