|
|
|
|
@ -179,14 +179,22 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Inserts the whole sequence into the items array, no updates |
|
|
|
|
public func append(contentOfs sequence: any Sequence<T>) throws { |
|
|
|
|
public func addOrUpdate(contentOfs sequence: any Sequence<T>) throws { |
|
|
|
|
defer { |
|
|
|
|
self._hasChanged = true |
|
|
|
|
} |
|
|
|
|
self.items.append(contentsOf: sequence) |
|
|
|
|
|
|
|
|
|
for instance in sequence { |
|
|
|
|
try self._sendInsertionIfNecessary(instance) |
|
|
|
|
if let index = self.items.firstIndex(where: { $0.id == instance.id }) { |
|
|
|
|
self.items[index] = instance |
|
|
|
|
try self._sendUpdateIfNecessary(instance) |
|
|
|
|
} else { // insert |
|
|
|
|
self.items.append(instance) |
|
|
|
|
self._index?[instance.stringId] = instance |
|
|
|
|
try self._sendInsertionIfNecessary(instance) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns the instance corresponding to the provided [id] |
|
|
|
|
@ -226,7 +234,7 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti |
|
|
|
|
/// Schedules a write operation |
|
|
|
|
fileprivate func _scheduleWrite() { |
|
|
|
|
if self.asynchronousIO { |
|
|
|
|
DispatchQueue(label: "lestorage.queue.write", qos: .utility).sync { // sync to make sure we don't have writes performed at the same time |
|
|
|
|
DispatchQueue(label: "lestorage.queue.write", qos: .utility).asyncAndWait { // sync to make sure we don't have writes performed at the same time |
|
|
|
|
self._write() |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
|