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

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

Loading…
Cancel
Save