Przeglądaj źródła

Devicestatus upload fix

Jonas Björkert 1 rok temu
rodzic
commit
dca96ff8df

+ 15 - 1
Trio/Sources/Services/Network/Nightscout/NightscoutManager.swift

@@ -84,6 +84,8 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
     private var coreDataPublisher: AnyPublisher<Set<NSManagedObjectID>, Never>?
     private var subscriptions = Set<AnyCancellable>()
 
+    private let debouncedQueue = DispatchQueue(label: "OrefDeterminationDebounce", qos: .utility)
+
     init(resolver: Resolver) {
         injectServices(resolver)
         subscribe()
@@ -131,7 +133,19 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
         /// 2. To not spam the user's NS site with a high number of uploads in a very short amount of time (less than 1sec)
         coreDataPublisher?
             .filteredByEntityName("OrefDetermination")
-            .debounce(for: .seconds(2), scheduler: DispatchQueue.global(qos: .background))
+            .handleEvents(receiveOutput: { _ in
+                debug(
+                    .nightscout,
+                    "OrefDetermination update"
+                )
+            })
+            .debounce(for: .seconds(2), scheduler: debouncedQueue)
+            .handleEvents(receiveOutput: { _ in
+                debug(
+                    .nightscout,
+                    "OrefDetermination update debounceed"
+                )
+            })
             .sink { [weak self] objectIDs in
                 guard let self = self else { return }