diff --git a/LeStorage/StoredCollection+Sync.swift b/LeStorage/StoredCollection+Sync.swift index eee6d7f..70274c8 100644 --- a/LeStorage/StoredCollection+Sync.swift +++ b/LeStorage/StoredCollection+Sync.swift @@ -59,6 +59,11 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable { /// to an object when it's inserted. The StoredCollection possibly needs to update its own copy with new values. /// - serverInstance: the instance of the object on the server func updateFromServerInstance(_ serverInstance: T) { + + guard T.copyServerResponse else { + return + } + DispatchQueue.main.async { if let localInstance = self.findById(serverInstance.id) { localInstance.copy(from: serverInstance) @@ -104,7 +109,7 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable { /// Adds or update an instance and writes public func addOrUpdate(instance: T) { - Logger.log("\(T.resourceName()) : one item") +// Logger.log("\(T.resourceName()) : one item") defer { self.setChanged() } @@ -121,7 +126,7 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable { /// Adds or update a sequence and writes public func addOrUpdate(contentOfs sequence: any Sequence) { - Logger.log("\(T.resourceName()) : \(sequence.underestimatedCount) items") +// Logger.log("\(T.resourceName()) : \(sequence.underestimatedCount) items") defer { self.setChanged() } diff --git a/LeStorage/StoredCollection.swift b/LeStorage/StoredCollection.swift index 1376ec9..3ca056e 100644 --- a/LeStorage/StoredCollection.swift +++ b/LeStorage/StoredCollection.swift @@ -257,7 +257,12 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti /// Updates an instance to the collection by index func updateItem(_ instance: T, index: Int) { - self.items[index].copy(from: instance) + + let item = self.items[index] + if item !== instance { + self.items[index].copy(from: instance) + } + instance.store = self.store self._indexes?[instance.id] = instance }