remove inappropriate logs

sync3
Laurent 6 months ago
parent e55f183053
commit 002cec1634
  1. 8
      LeStorage/Store.swift
  2. 28
      LeStorage/StoreCenter.swift
  3. 13
      LeStorage/StoredSingleton.swift
  4. 3
      LeStorage/SyncedCollection.swift

@ -15,7 +15,6 @@ public enum StoreError: Error, LocalizedError {
case missingToken
case missingKeychainStore
case collectionNotRegistered(type: String)
case cannotSyncCollection(name: String)
case apiCallCollectionNotRegistered(type: String)
public var errorDescription: String? {
@ -32,8 +31,6 @@ public enum StoreError: Error, LocalizedError {
return "There is no keychain store"
case .collectionNotRegistered(let type):
return "The collection \(type) is not registered"
case .cannotSyncCollection(let name):
return "Tries to load the collection \(name) from the server while it's not authorized"
case .apiCallCollectionNotRegistered(let type):
return "The api call collection has not been registered for \(type)"
}
@ -127,9 +124,10 @@ final public class Store {
/// - synchronized: indicates if the data is synchronized with the server
/// - inMemory: Indicates if the collection should only live in memory, and not write into a file
/// - sendsUpdate: Indicates if updates of items should be sent to the server
public func registerObject<T : Storable>(synchronized: Bool, inMemory: Bool = false, sendsUpdate: Bool = true) -> StoredSingleton<T> {
public func registerObject<T : Storable>(synchronized: Bool, inMemory: Bool = false, shouldLoadDataFromServer: Bool = true) -> StoredSingleton<T> {
let storedObject = StoredSingleton<T>(store: self, inMemory: inMemory)
let storedObject = StoredSingleton<T>(store: self, inMemory: inMemory, shouldLoadDataFromServer: shouldLoadDataFromServer)
self._collections[T.resourceName()] = storedObject
self._collections[T.resourceName()] = storedObject
if synchronized {

@ -64,6 +64,9 @@ public class StoreCenter {
/// Used for testing, gives the project name to retrieve classes from names
var classProject: String? = nil
var useWebsockets: Bool = false
var useSynchronization: Bool = false
init(directoryName: String? = nil) {
@ -87,22 +90,31 @@ public class StoreCenter {
}
public func configureURLs(secureScheme: Bool, domain: String, webSockets: Bool = true) {
self.useWebsockets = webSockets
let urlManager: URLManager = URLManager(secureScheme: secureScheme, domain: domain)
self._urlManager = urlManager
self._services = Services(storeCenter: self, url: urlManager.api)
self.tokenKeychain = KeychainStore(serverId: urlManager.api)
self._dataAccess = self.mainStore.registerSynchronizedCollection()
if self.useSynchronization {
self._dataAccess = self.mainStore.registerSynchronizedCollection()
}
Logger.log("Sync URL: \(urlManager.api)")
if webSockets && self.userId != nil {
if self.userId != nil {
self._configureWebSocket()
}
}
fileprivate func _configureWebSocket() {
guard self.useWebsockets else {
return
}
self._webSocketManager?.disconnect()
self._webSocketManager = nil
@ -540,11 +552,13 @@ public class StoreCenter {
self.mainStore.loadCollectionsFromServer(clear: clear)
// request data that has been shared with the user
Task {
do {
try await self.service().getUserDataAccess()
} catch {
Logger.error(error)
if self.useSynchronization {
Task {
do {
try await self.service().getUserDataAccess()
} catch {
Logger.error(error)
}
}
}

@ -10,6 +10,19 @@ import Foundation
/// A class extending the capabilities of StoredCollection but supposedly manages only one item
public class StoredSingleton<T: SyncedStorable>: SyncedCollection<T> {
var shouldLoadDataFromServer: Bool = true
init(store: Store, inMemory: Bool = false, shouldLoadDataFromServer: Bool = true) {
super.init(store: store, inMemory: inMemory)
self.shouldLoadDataFromServer = shouldLoadDataFromServer
}
public override func loadDataFromServerIfAllowed(clear: Bool = false) async throws {
if shouldLoadDataFromServer {
try await super.loadDataFromServerIfAllowed(clear: clear)
}
}
/// Sets the singleton to the collection without synchronizing it
public func setItemNoSync(_ instance: T) {
self.setSingletonNoSync(instance: instance)

@ -46,9 +46,6 @@ public class SyncedCollection<T : SyncedStorable>: BaseCollection<T>, SomeSynced
/// Retrieves the data from the server and loads it into the items array
public func loadDataFromServerIfAllowed(clear: Bool = false) async throws {
guard !(self is StoredSingleton<T>) else {
throw StoreError.cannotSyncCollection(name: self.resourceName)
}
do {
try await self.storeCenter.sendGetRequest(T.self, storeId: self.storeId, clear: clear)
} catch {

Loading…
Cancel
Save