sync2
Laurent 8 months ago
commit 4c4cc246b9
  1. 11
      LeStorage/StoredCollection.swift

@ -65,7 +65,6 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
fileprivate(set) var limit: Int? = nil
init(store: Store, indexed: Bool = false, inMemory: Bool = false, limit: Int? = nil) {
if indexed {
self._indexes = [:]
@ -92,6 +91,10 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
return T.resourceName()
}
public var storeId: String? {
return self.store.identifier
}
// MARK: - Loading
/// Sets the collection as changed to trigger a write
@ -337,7 +340,8 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
try self.store.write(content: jsonString, fileName: T.fileName())
} catch {
Logger.error(error)
StoreCenter.main.log(message: "write failed for \(T.resourceName()): \(error.localizedDescription)")
StoreCenter.main.log(
message: "write failed for \(T.resourceName()): \(error.localizedDescription)")
}
}
@ -362,7 +366,8 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
guard relationships.count > 0 else { return 0 }
return self.items.reduce(0) { count, item in
count + relationships.filter { relationship in
count
+ relationships.filter { relationship in
(item[keyPath: relationship.keyPath] as? String) == id
}.count
}

Loading…
Cancel
Save