Skip to content

Commit

Permalink
Flush delta queue on start
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Rodrigo Gomez Palacio committed Sep 30, 2024
1 parent eeb702c commit 7f07d0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -107,14 +108,19 @@ 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
}
start()
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7f07d0a

Please sign in to comment.