Skip to content
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

Improve thread DB access handling #1290

Merged
merged 5 commits into from
Mar 17, 2021
Merged

Conversation

Jeasmine
Copy link
Contributor

@Jeasmine Jeasmine commented Mar 12, 2021

The Problem

isDuplicateNotification methods sometimes ended called on the main thread, this can en on an ANR is Notification table is being blocked by other thread.

Solution

Move all database access from OneSignal.java to the new class OSNotificationDataController. In the future, we will want all notification table access to be on the same class to have a single responsible class, also to have few threads handling notification table access.

Move outcome table access to OSOutcomeEventsCache

  • OneSignalCacheCleaner shouldn't have access to the outcome table when we have a class responsible for managing the outcome database table

Move IAM cache cleaning to OSInAppMessageController

  • IAM database access and all regarding IAM should live in OSInAppMessageController

Rename OneSignalCacheCleaner to OSNotificationDataController

  • OSNotificationDataController will be the new class responsible for handling notification table access

Move OneSignal db access to OSNotificationDataController

  • Move clearOneSignalNotifications from OneSignal.java to OSNotificationDataController
  • Move removeGroupedNotifications from OneSignal.java to OSNotificationDataController
  • Move removeNotification from OneSignal.java to OSNotificationDataController
  • Move isDuplicateNotification from OneSignal.java to OSNotificationDataController
  • isDuplicateNotification no longer returns a boolean, all methods using isDuplicateNotification wait for callback result

Fix #1284

This change is Reviewable

@Jeasmine Jeasmine force-pushed the improvement/thread-access-db branch from 5332055 to 37ba46d Compare March 12, 2021 22:51
@Jeasmine Jeasmine added the WIP Work In Progress label Mar 12, 2021
@Jeasmine Jeasmine force-pushed the improvement/thread-access-db branch from e1f091e to 83560d7 Compare March 15, 2021 19:04
* OneSignalCacheCleaner shouldn't have access to the outcome table when we have a class responsible for managing the outcome database table
* IAM database access and all regarding IAM should live in OSInAppMessageController
* OSNotificationDataController will be the new class responsible for handling notification table access
* Move clearOneSignalNotifications from OneSignal.java to OSNotificationDataController
* Move removeGroupedNotifications from OneSignal.java to OSNotificationDataController
* Move removeNotification from OneSignal.java to OSNotificationDataController
* Move isDuplicateNotification from OneSignal.java to OSNotificationDataController
* isDuplicateNotification no longer returns a boolean, all methods using isDuplicateNotification wait for callback result
@Jeasmine Jeasmine force-pushed the improvement/thread-access-db branch from 83560d7 to 47ae123 Compare March 15, 2021 19:11
@Jeasmine Jeasmine changed the title WIP - Improve thread DB access handling Improve thread DB access handling Mar 15, 2021
@Jeasmine Jeasmine force-pushed the improvement/thread-access-db branch from 01b1877 to a2b9fd4 Compare March 15, 2021 22:35
@Jeasmine Jeasmine force-pushed the improvement/thread-access-db branch from a2b9fd4 to b5b1792 Compare March 15, 2021 22:55
@Jeasmine Jeasmine removed the WIP Work In Progress label Mar 15, 2021
@Jeasmine Jeasmine requested a review from jkasten2 March 15, 2021 23:12
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

Reviewed 21 of 21 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Jeasmine)


OneSignalSDK/onesignal/src/main/java/com/onesignal/ADMMessageHandlerJob.kt, line 17 at r1 (raw file):

                //      FCMBroadcastReceiver.completeWakefulIntent(intent);

                processedResult?.let {

Not sure what the best practices in general are for Kotlin but I think it would be cleaner like this.

if (processedResult?.processed() == true) return

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationBundleProcessor.java, line 374 at r1 (raw file):

        maximizeButtonsFromBundle(bundle);

        if (inAppMessagePreviewHandled(bundleResult, bundle)) {

👍 Nice clean up on moving the preview logic to it's own method.

Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

👍 Lots of good clean up in this PR!

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Jeasmine)

Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Jeasmine)


OneSignalSDK/onesignal/src/main/java/com/onesignal/ADMMessageHandlerJob.kt, line 17 at r1 (raw file):

Previously, jkasten2 (Josh Kasten) wrote…

Not sure what the best practices in general are for Kotlin but I think it would be cleaner like this.

if (processedResult?.processed() == true) return

This is really more of a nit, not a blocker.

@jkasten2 jkasten2 merged commit 4a5fa0d into master Mar 17, 2021
@Jeasmine Jeasmine deleted the improvement/thread-access-db branch July 10, 2021 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ANR at com.onesignal.OneSignalDbHelper.query (OneSignalDbHelper.java:187)
2 participants