|
|
|
|
@ -190,12 +190,13 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
do { |
|
|
|
|
let items: [T] = try await self._store.getItems() |
|
|
|
|
if items.count > 0 { |
|
|
|
|
try self._addOrUpdate(contentOfs: items, shouldSync: false) |
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
self._addOrUpdate(contentOfs: items, shouldSync: false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
self._setAsLoaded() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Loads the collection using the server data only if the collection file doesn't exists |
|
|
|
|
@ -279,16 +280,16 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
|
|
|
|
|
/// Adds or update a sequence of elements |
|
|
|
|
public func addOrUpdate(contentOfs sequence: any Sequence<T>) throws { |
|
|
|
|
try self._addOrUpdate(contentOfs: sequence) |
|
|
|
|
self._addOrUpdate(contentOfs: sequence) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Adds or update a sequence of elements without synchronizing it |
|
|
|
|
func addOrUpdateNoSync(contentOfs sequence: any Sequence<T>) throws { |
|
|
|
|
try self._addOrUpdate(contentOfs: sequence, shouldSync: false) |
|
|
|
|
self._addOrUpdate(contentOfs: sequence, shouldSync: false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Inserts or updates all items in the sequence |
|
|
|
|
fileprivate func _addOrUpdate(contentOfs sequence: any Sequence<T>, shouldSync: Bool = true) throws { |
|
|
|
|
fileprivate func _addOrUpdate(contentOfs sequence: any Sequence<T>, shouldSync: Bool = true) { |
|
|
|
|
defer { |
|
|
|
|
self._hasChanged = true |
|
|
|
|
} |
|
|
|
|
|