Skip to content

Commit 7f07d0a

Browse files
author
Rodrigo Gomez Palacio
committed
Flush delta queue on start
Motivation: we need to flush the delta queue on start in order to immediately trigger updates that would return a RYW token so we can unblock IAM fetch as soon as possible.
1 parent eeb702c commit 7f07d0a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import OneSignalCore
3535
public class OSOperationRepo: NSObject {
3636
public static let sharedInstance = OSOperationRepo()
3737
private var hasCalledStart = false
38+
private var sessionCountDeltaQueued = false // used to know when to force-flush
3839

3940
// The Operation Repo dispatch queue, serial. This synchronizes access to `deltaQueue` and flushing behavior.
4041
private let dispatchQueue = DispatchQueue(label: "OneSignal.OSOperationRepo", target: .global())
@@ -107,14 +108,19 @@ public class OSOperationRepo: NSObject {
107108
// TODO: We can make this method internal once there is no manual adding of a Delta except through stores.
108109
This can happen when session data and purchase data use the model / store / listener infrastructure.
109110
*/
110-
public func enqueueDelta(_ delta: OSDelta) {
111+
public func enqueueDelta(_ delta: OSDelta, flush: Bool = false) {
111112
guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else {
112113
return
113114
}
114115
start()
115116
self.dispatchQueue.async {
116117
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSOperationRepo enqueueDelta: \(delta)")
117118
self.deltaQueue.append(delta)
119+
120+
if flush {
121+
self.flushDeltaQueue()
122+
}
123+
118124
// Persist the deltas (including new delta) to storage
119125
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_OPERATION_REPO_DELTA_QUEUE_KEY, withValue: self.deltaQueue)
120126
}

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ extension OneSignalUserManagerImpl {
583583
property: property.rawValue,
584584
value: value
585585
)
586-
OSOperationRepo.sharedInstance.enqueueDelta(delta)
586+
OSOperationRepo.sharedInstance.enqueueDelta(delta, flush: true)
587587
}
588588

589589
/// Time processors forward the session time to this method.

0 commit comments

Comments
 (0)