Improve rescheduling

sync2
Laurent 8 months ago
parent ba3bacb906
commit c5168f1ace
  1. 3
      LeStorage/ApiCallCollection.swift
  2. 62
      LeStorage/StoredCollection+Sync.swift

@ -164,6 +164,7 @@ actor ApiCallCollection<T: SyncedStorable>: SomeCallCollection {
}
}
/// Reschedule API calls without waiting
func rescheduleImmediately() {
self._attemptLoops = -1
self.rescheduleApiCallsIfNecessary()
@ -333,7 +334,7 @@ actor ApiCallCollection<T: SyncedStorable>: SomeCallCollection {
let call = try self.callForInstance(delete, method: .delete, transactionId: transactionId)
apiCalls.append(call)
}
self.rescheduleApiCallsIfNecessary()
self.rescheduleImmediately()
// return try await self._executeApiCalls(apiCalls)
}

@ -80,37 +80,8 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable {
}
}
// MARK: - Basic operations
// MARK: - Basic operations with sync
/// Adds or update an instance without synchronizing it
func addOrUpdateNoSync(_ instance: T) throws {
self.addOrUpdateItem(instance: instance)
}
/// Adds or update a sequence of elements without synchronizing it
func addOrUpdateNoSync(contentOfs sequence: any Sequence<T>) {
self.addSequence(sequence)
}
/// Deletes the instance in the collection without synchronization
func deleteNoSync(instance: T) throws {
defer {
self.setChanged()
}
self.deleteItem(instance)
}
/// Deletes the instance in the collection without synchronization
func deleteByStringIdNoSync(_ id: String) {
defer {
self.setChanged()
}
let realId = T.buildRealId(id: id)
if let instance = self.findById(realId) {
self.deleteItem(instance)
}
}
/// Adds or update an instance and writes
public func addOrUpdate(instance: T) {
// Logger.log("\(T.resourceName()) : one item")
@ -201,6 +172,37 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable {
delete(contentOfs: items) // MUST NOT ADD "self" before delete, otherwise it will call the delete method of StoredCollection without sync
}
// MARK: - Basic operations without sync
/// Adds or update an instance without synchronizing it
func addOrUpdateNoSync(_ instance: T) throws {
self.addOrUpdateItem(instance: instance)
}
/// Adds or update a sequence of elements without synchronizing it
func addOrUpdateNoSync(contentOfs sequence: any Sequence<T>) {
self.addSequence(sequence)
}
/// Deletes the instance in the collection without synchronization
func deleteNoSync(instance: T) throws {
defer {
self.setChanged()
}
self.deleteItem(instance)
}
/// Deletes the instance in the collection without synchronization
func deleteByStringIdNoSync(_ id: String) {
defer {
self.setChanged()
}
let realId = T.buildRealId(id: id)
if let instance = self.findById(realId) {
self.deleteItem(instance)
}
}
// MARK: - Send requests
fileprivate func _sendInsertion(_ instance: T) {

Loading…
Cancel
Save