Prevent potential duplicate calls to CreateDevice
#6023
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


🎯 Goal
We still have reports of the
CreateDeviceendpoint hitting rate limits. In this PR we introduce another level of guarding against duplicate calls, by introducing a local tracking of the device registered in the current session, plus a locking mechanism.🛠 Implementation details
CreateDevice/DeleteDeviceendpoints will fail if called without a connected user) to support the case where different users a switched in the sameChatClientPushTokenUpdateHandler#addDevice: check if the same token was registered previously in the current session (in addition to the check againsuser.devices)CreateDeviceinvocations at the same timeDeviceApiandChatApiby removing unnecessary parameters🎨 UI Changes
NA
🧪 Testing
Pretty difficult to test in a real-world scenario. One possible scenario to test is to manually delete the firebase token:
FirebaseMessaging.getInstance().deleteToken()Then put the app in background, and then back to foreground. There should be two attempts to register the new token:
onNewTokenBut only one
CreateDeviceshould be fired.Another possibility is to simulate repeated calls to
FirebaseMessagingDelegate.registerPushDevice- again, only oneCreateDeviceshould be fired.