Skip to content

Commit eb58e4f

Browse files
committed
no logic change - organize executor startup code
* No logic changes here, just break up executor code into digestible functions
1 parent eede113 commit eb58e4f

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSIdentityOperationExecutor.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
3939
private let dispatchQueue = DispatchQueue(label: "OneSignal.OSIdentityOperationExecutor", target: .global())
4040

4141
init() {
42-
// Read unfinished deltas from cache, if any...
42+
// Read unfinished deltas and requests from cache, if any...
43+
uncacheDeltas()
44+
uncacheAddAliasRequests()
45+
uncacheRemoveAliasRequests()
46+
}
47+
48+
private func uncacheDeltas() {
4349
if var deltaQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_IDENTITY_EXECUTOR_DELTA_QUEUE_KEY, defaultValue: []) as? [OSDelta] {
4450
// Hook each uncached Delta to the model in the store
4551
for (index, delta) in deltaQueue.enumerated().reversed() {
@@ -57,9 +63,9 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
5763
} else {
5864
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSIdentityOperationExecutor error encountered reading from cache for \(OS_IDENTITY_EXECUTOR_DELTA_QUEUE_KEY)")
5965
}
66+
}
6067

61-
// Read unfinished requests from cache, if any...
62-
68+
private func uncacheAddAliasRequests() {
6369
if var addRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_IDENTITY_EXECUTOR_ADD_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestAddAliases] {
6470
// Hook each uncached Request to the model in the store
6571
for (index, request) in addRequestQueue.enumerated().reversed() {
@@ -80,7 +86,9 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
8086
} else {
8187
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSIdentityOperationExecutor error encountered reading from cache for \(OS_IDENTITY_EXECUTOR_ADD_REQUEST_QUEUE_KEY)")
8288
}
89+
}
8390

91+
private func uncacheRemoveAliasRequests() {
8492
if var removeRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_IDENTITY_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestRemoveAlias] {
8593
// Hook each uncached Request to the model in the store
8694
for (index, request) in removeRequestQueue.enumerated().reversed() {

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSPropertyOperationExecutor.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
6969
private let dispatchQueue = DispatchQueue(label: "OneSignal.OSPropertyOperationExecutor", target: .global())
7070

7171
init() {
72-
// Read unfinished deltas from cache, if any...
72+
// Read unfinished deltas and requests from cache, if any...
7373
// Note that we should only have deltas for the current user as old ones are flushed..
74+
uncacheDeltas()
75+
uncacheUpdateRequests()
76+
}
77+
78+
private func uncacheDeltas() {
7479
if var deltaQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_PROPERTIES_EXECUTOR_DELTA_QUEUE_KEY, defaultValue: []) as? [OSDelta] {
7580
for (index, delta) in deltaQueue.enumerated().reversed() {
7681
if OneSignalUserManagerImpl.sharedInstance.getIdentityModel(delta.identityModelId) == nil {
@@ -84,8 +89,9 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
8489
} else {
8590
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSPropertyOperationExecutor error encountered reading from cache for \(OS_PROPERTIES_EXECUTOR_DELTA_QUEUE_KEY)")
8691
}
92+
}
8793

88-
// Read unfinished requests from cache, if any...
94+
private func uncacheUpdateRequests() {
8995
if var updateRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_PROPERTIES_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestUpdateProperties] {
9096
// Hook each uncached Request to the model in the store
9197
for (index, request) in updateRequestQueue.enumerated().reversed() {

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSSubscriptionOperationExecutor.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
4141
private let dispatchQueue = DispatchQueue(label: "OneSignal.OSSubscriptionOperationExecutor", target: .global())
4242

4343
init() {
44-
// Read unfinished deltas from cache, if any...
44+
// Read unfinished deltas and requests from cache, if any...
45+
uncacheDeltas()
46+
uncacheCreateSubscriptionRequests()
47+
uncacheDeleteSubscriptionRequests()
48+
uncacheUpdateSubscriptionRequests()
49+
}
50+
51+
private func uncacheDeltas() {
4552
if var deltaQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_DELTA_QUEUE_KEY, defaultValue: []) as? [OSDelta] {
4653
// Hook each uncached Delta to the model in the store
4754
for (index, delta) in deltaQueue.enumerated().reversed() {
@@ -59,9 +66,9 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
5966
} else {
6067
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSSubscriptionOperationExecutor error encountered reading from cache for \(OS_SUBSCRIPTION_EXECUTOR_DELTA_QUEUE_KEY)")
6168
}
69+
}
6270

63-
// Read unfinished requests from cache, if any...
64-
71+
private func uncacheCreateSubscriptionRequests() {
6572
var requestQueue: [OSRequestCreateSubscription] = []
6673

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

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

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

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ class OSUserExecutor {
3939
// The User executor dispatch queue, serial. This synchronizes access to the request queues.
4040
private let dispatchQueue = DispatchQueue(label: "OneSignal.OSUserExecutor", target: .global())
4141

42-
// Read in requests from the cache, do not read in FetchUser requests as this is not needed.
4342
init() {
43+
uncacheUserRequests()
44+
migrateTransferSubscriptionRequests()
45+
executePendingRequests()
46+
}
47+
48+
// Read in requests from the cache, do not read in FetchUser requests as this is not needed.
49+
private func uncacheUserRequests() {
4450
var userRequestQueue: [OSUserRequest] = []
4551

4652
// Read unfinished Create User + Identify User + Get Identity By Subscription requests from cache, if any...
@@ -97,9 +103,6 @@ class OSUserExecutor {
97103
}
98104
self.userRequestQueue = userRequestQueue
99105
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_USER_EXECUTOR_USER_REQUEST_QUEUE_KEY, withValue: self.userRequestQueue)
100-
101-
migrateTransferSubscriptionRequests()
102-
executePendingRequests()
103106
}
104107

105108
/**

0 commit comments

Comments
 (0)