Skip to content

Commit

Permalink
Merge pull request #1465 from OneSignal/fix/user_executor_starts_first
Browse files Browse the repository at this point in the history
[Bug] The user executor needs to uncache before other executors
  • Loading branch information
nan-li authored Aug 2, 2024
2 parents d419c8e + eb58e4f commit 836c73a
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
private let dispatchQueue = DispatchQueue(label: "OneSignal.OSIdentityOperationExecutor", target: .global())

init() {
// Read unfinished deltas from cache, if any...
// Read unfinished deltas and requests from cache, if any...
uncacheDeltas()
uncacheAddAliasRequests()
uncacheRemoveAliasRequests()
}

private func uncacheDeltas() {
if var deltaQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_IDENTITY_EXECUTOR_DELTA_QUEUE_KEY, defaultValue: []) as? [OSDelta] {
// Hook each uncached Delta to the model in the store
for (index, delta) in deltaQueue.enumerated().reversed() {
Expand All @@ -57,9 +63,9 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
} else {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSIdentityOperationExecutor error encountered reading from cache for \(OS_IDENTITY_EXECUTOR_DELTA_QUEUE_KEY)")
}
}

// Read unfinished requests from cache, if any...

private func uncacheAddAliasRequests() {
if var addRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_IDENTITY_EXECUTOR_ADD_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestAddAliases] {
// Hook each uncached Request to the model in the store
for (index, request) in addRequestQueue.enumerated().reversed() {
Expand All @@ -80,7 +86,9 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
} else {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSIdentityOperationExecutor error encountered reading from cache for \(OS_IDENTITY_EXECUTOR_ADD_REQUEST_QUEUE_KEY)")
}
}

private func uncacheRemoveAliasRequests() {
if var removeRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_IDENTITY_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestRemoveAlias] {
// Hook each uncached Request to the model in the store
for (index, request) in removeRequestQueue.enumerated().reversed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
private let dispatchQueue = DispatchQueue(label: "OneSignal.OSPropertyOperationExecutor", target: .global())

init() {
// Read unfinished deltas from cache, if any...
// Read unfinished deltas and requests from cache, if any...
// Note that we should only have deltas for the current user as old ones are flushed..
uncacheDeltas()
uncacheUpdateRequests()
}

private func uncacheDeltas() {
if var deltaQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_PROPERTIES_EXECUTOR_DELTA_QUEUE_KEY, defaultValue: []) as? [OSDelta] {
for (index, delta) in deltaQueue.enumerated().reversed() {
if OneSignalUserManagerImpl.sharedInstance.getIdentityModel(delta.identityModelId) == nil {
Expand All @@ -84,8 +89,9 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
} else {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSPropertyOperationExecutor error encountered reading from cache for \(OS_PROPERTIES_EXECUTOR_DELTA_QUEUE_KEY)")
}
}

// Read unfinished requests from cache, if any...
private func uncacheUpdateRequests() {
if var updateRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_PROPERTIES_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestUpdateProperties] {
// Hook each uncached Request to the model in the store
for (index, request) in updateRequestQueue.enumerated().reversed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
private let dispatchQueue = DispatchQueue(label: "OneSignal.OSSubscriptionOperationExecutor", target: .global())

init() {
// Read unfinished deltas from cache, if any...
// Read unfinished deltas and requests from cache, if any...
uncacheDeltas()
uncacheCreateSubscriptionRequests()
uncacheDeleteSubscriptionRequests()
uncacheUpdateSubscriptionRequests()
}

private func uncacheDeltas() {
if var deltaQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_DELTA_QUEUE_KEY, defaultValue: []) as? [OSDelta] {
// Hook each uncached Delta to the model in the store
for (index, delta) in deltaQueue.enumerated().reversed() {
Expand All @@ -59,9 +66,9 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
} else {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSSubscriptionOperationExecutor error encountered reading from cache for \(OS_SUBSCRIPTION_EXECUTOR_DELTA_QUEUE_KEY)")
}
}

// Read unfinished requests from cache, if any...

private func uncacheCreateSubscriptionRequests() {
var requestQueue: [OSRequestCreateSubscription] = []

if let cachedAddRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_ADD_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestCreateSubscription] {
Expand Down Expand Up @@ -97,7 +104,9 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
} else {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSSubscriptionOperationExecutor error encountered reading from cache for \(OS_SUBSCRIPTION_EXECUTOR_ADD_REQUEST_QUEUE_KEY)")
}
}

private func uncacheDeleteSubscriptionRequests() {
if var removeRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestDeleteSubscription] {
// Hook each uncached Request to the model in the store
for (index, request) in removeRequestQueue.enumerated().reversed() {
Expand All @@ -118,7 +127,9 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
} else {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSSubscriptionOperationExecutor error encountered reading from cache for \(OS_SUBSCRIPTION_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY)")
}
}

private func uncacheUpdateSubscriptionRequests() {
if var updateRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestUpdateSubscription] {
// Hook each uncached Request to the model in the store
for (index, request) in updateRequestQueue.enumerated().reversed() {
Expand Down
Loading

0 comments on commit 836c73a

Please sign in to comment.