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

[Bug] The user executor needs to uncache before other executors #1465

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading