From 7f07d0a335a68e4e782a30b234fb4d526bd02104 Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Tue, 17 Sep 2024 16:02:26 -0500 Subject: [PATCH] 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. --- .../OneSignalOSCore/Source/OSOperationRepo.swift | 8 +++++++- .../OneSignalUser/Source/OneSignalUserManagerImpl.swift | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift index 338fadd50..0f25e5a47 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift @@ -35,6 +35,7 @@ import OneSignalCore public class OSOperationRepo: NSObject { public static let sharedInstance = OSOperationRepo() private var hasCalledStart = false + private var sessionCountDeltaQueued = false // used to know when to force-flush // The Operation Repo dispatch queue, serial. This synchronizes access to `deltaQueue` and flushing behavior. private let dispatchQueue = DispatchQueue(label: "OneSignal.OSOperationRepo", target: .global()) @@ -107,7 +108,7 @@ public class OSOperationRepo: NSObject { // TODO: We can make this method internal once there is no manual adding of a Delta except through stores. This can happen when session data and purchase data use the model / store / listener infrastructure. */ - public func enqueueDelta(_ delta: OSDelta) { + public func enqueueDelta(_ delta: OSDelta, flush: Bool = false) { guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { return } @@ -115,6 +116,11 @@ public class OSOperationRepo: NSObject { self.dispatchQueue.async { OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSOperationRepo enqueueDelta: \(delta)") self.deltaQueue.append(delta) + + if flush { + self.flushDeltaQueue() + } + // Persist the deltas (including new delta) to storage OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_OPERATION_REPO_DELTA_QUEUE_KEY, withValue: self.deltaQueue) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index 77ecd4c79..4c52f5de0 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -583,7 +583,7 @@ extension OneSignalUserManagerImpl { property: property.rawValue, value: value ) - OSOperationRepo.sharedInstance.enqueueDelta(delta) + OSOperationRepo.sharedInstance.enqueueDelta(delta, flush: true) } /// Time processors forward the session time to this method.