sync
Laurent 1 year ago
parent 3044bc23aa
commit f5d3972eba
  1. 1
      LeStorage/Store.swift
  2. 1
      LeStorage/StoreCenter.swift
  3. 11
      LeStorage/StoredCollection.swift
  4. 2
      LeStorage/Utils/Codable+Extensions.swift
  5. 2
      LeStorage/Utils/Logger.swift

@ -240,7 +240,6 @@ open class Store {
/// Loads all synchronized collection with server data if they don't already have a local file
public func loadCollectionsFromServerIfNoFile() {
for collection in self._collections.values {
// Logger.log("Load \(name)")
if collection.synchronized {
Task {
do {

@ -354,7 +354,6 @@ public class StoreCenter {
public func destroyStore(identifier: String) {
let directory = "\(Store.storageDirectory)/\(identifier)"
FileManager.default.deleteDirectoryInDocuments(directoryName: directory)
self._stores.removeValue(forKey: identifier)
}

@ -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
}

@ -10,7 +10,7 @@ import Foundation
fileprivate var jsonEncoder: JSONEncoder = {
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
#if _DEBUG_OPTIONS
#if DEBUG
encoder.outputFormatting = .prettyPrinted
#endif
encoder.dateEncodingStrategy = .iso8601

@ -40,7 +40,7 @@ import Foundation
@objc static public func crashLogging(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
let fileName: String = file.components(separatedBy: "/").last ?? file
#if _DEBUG_OPTIONS
#if DEBUG
NSLogv("%@.%i.%@: %@", getVaList([fileName, line, function, message]))
#else
//Crashlytics.crashlytics().log(format: "%@.%i.%@: %@", arguments: getVaList([fileName, line, function, message]))

Loading…
Cancel
Save