diff --git a/LeStorage/Codables/ApiCall.swift b/LeStorage/Codables/ApiCall.swift index 216b863..c9879b6 100644 --- a/LeStorage/Codables/ApiCall.swift +++ b/LeStorage/Codables/ApiCall.swift @@ -8,7 +8,6 @@ import Foundation protocol SomeCall: Storable { -// func execute() throws var lastAttemptDate: Date { get } } @@ -44,11 +43,4 @@ class ApiCall: ModelObject, Storable, SomeCall { self.body = body } - /// Executes the api call -// func execute() throws { -// Task { -// try await Store.main.execute(apiCall: self) -// } -// } - } diff --git a/LeStorage/Store.swift b/LeStorage/Store.swift index 30dca12..44bf0b9 100644 --- a/LeStorage/Store.swift +++ b/LeStorage/Store.swift @@ -255,7 +255,7 @@ public class Store { } public func hasPendingAPICalls() -> Bool { - return self._collections.values.allSatisfy { $0.hasPendingAPICalls() } + return self._collections.values.contains(where: { $0.hasPendingAPICalls() }) } } diff --git a/LeStorage/StoredCollection.swift b/LeStorage/StoredCollection.swift index b758845..f7865cd 100644 --- a/LeStorage/StoredCollection.swift +++ b/LeStorage/StoredCollection.swift @@ -294,13 +294,20 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti } /// Proceeds to "hard" delete the items without synchronizing them + /// Also removes related API calls public func deleteDependencies(_ items: any Sequence) { defer { self._hasChanged = true } for item in items { self.items.removeAll(where: { $0.id == item.id }) + + /// remove related API call if existing + if let apiCallIndex = self.apiCallsCollection?.firstIndex(where: { $0.dataId == item.id }) { + self.apiCallsCollection?.items.remove(at: apiCallIndex) + } } + } public func deleteAll() throws {