|
|
|
|
@ -62,8 +62,8 @@ public class StoreCenter { |
|
|
|
|
/// The URL manager |
|
|
|
|
fileprivate var _urlManager: URLManager? = nil |
|
|
|
|
|
|
|
|
|
/// Used for testing, gives the project name to retrieve classes from names |
|
|
|
|
var classProject: String? = nil |
|
|
|
|
/// Gives the project name to retrieve classes from names |
|
|
|
|
public var classProject: String? = nil |
|
|
|
|
|
|
|
|
|
var useWebsockets: Bool = false |
|
|
|
|
var useSynchronization: Bool = false |
|
|
|
|
@ -640,14 +640,14 @@ public class StoreCenter { |
|
|
|
|
/// Processes the data coming from a sync request |
|
|
|
|
@MainActor func synchronizeContent(_ syncData: SyncData) async { |
|
|
|
|
|
|
|
|
|
self._syncAddOrUpdate(syncData.updates) |
|
|
|
|
await self._syncAddOrUpdate(syncData.updates) |
|
|
|
|
await self._syncDelete(syncData.deletions) |
|
|
|
|
self._syncAddOrUpdate(syncData.grants, shared: true) |
|
|
|
|
await self._syncAddOrUpdate(syncData.grants, shared: true) |
|
|
|
|
await self.syncRevoke(syncData.revocations, parents: syncData.revocationParents) |
|
|
|
|
// self._syncAddOrUpdate(syncData.relationshipSets) |
|
|
|
|
// await self._syncDelete(syncData.relationshipRemovals) |
|
|
|
|
self._syncAddOrUpdate(syncData.sharedRelationshipSets, shared: true) |
|
|
|
|
self._syncRevoke(syncData.sharedRelationshipRemovals) |
|
|
|
|
await self._syncAddOrUpdate(syncData.sharedRelationshipSets, shared: true) |
|
|
|
|
await self._syncRevoke(syncData.sharedRelationshipRemovals) |
|
|
|
|
|
|
|
|
|
Logger.log("sync content: updates = \(syncData.updates.count) / deletions = \(syncData.deletions.count), grants = \(syncData.grants.count)") |
|
|
|
|
|
|
|
|
|
@ -667,12 +667,13 @@ public class StoreCenter { |
|
|
|
|
/// - Parameters: |
|
|
|
|
/// - updateArrays: the server updates |
|
|
|
|
/// - shared: indicates if the content should be flagged as shared |
|
|
|
|
@MainActor func _syncAddOrUpdate(_ updateArrays: [SyncedStorableArray], shared: Bool = false) { |
|
|
|
|
@MainActor |
|
|
|
|
func _syncAddOrUpdate(_ updateArrays: [SyncedStorableArray], shared: Bool = false) async { |
|
|
|
|
|
|
|
|
|
for updateArray in updateArrays { |
|
|
|
|
for item in updateArray.items { |
|
|
|
|
let storeId: String? = item.getStoreId() |
|
|
|
|
self.synchronizationAddOrUpdate(item, storeId: storeId, shared: shared) |
|
|
|
|
await self.synchronizationAddOrUpdate(item, storeId: storeId, shared: shared) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -692,7 +693,7 @@ public class StoreCenter { |
|
|
|
|
/// Processes data that has been revoked |
|
|
|
|
fileprivate func syncRevoke(_ revokedArrays: [ObjectIdentifierArray], parents: [[ObjectIdentifierArray]]) async { |
|
|
|
|
|
|
|
|
|
self._syncRevoke(revokedArrays) |
|
|
|
|
await self._syncRevoke(revokedArrays) |
|
|
|
|
for revokedArray in revokedArrays { |
|
|
|
|
for revoked in revokedArray.items { |
|
|
|
|
await self.synchronizationDelete(id: revoked.modelId, type: revokedArray.type, storeId: revoked.storeId) // or synchronizationRevoke ? |
|
|
|
|
@ -700,17 +701,14 @@ public class StoreCenter { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for level in parents { |
|
|
|
|
self._syncRevoke(level) |
|
|
|
|
await self._syncRevoke(level) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _syncRevoke(_ revokeArrays: [ObjectIdentifierArray]) { |
|
|
|
|
|
|
|
|
|
Task { |
|
|
|
|
for revokeArray in revokeArrays { |
|
|
|
|
for revoked in revokeArray.items { |
|
|
|
|
await self.synchronizationRevoke(id: revoked.modelId, type: revokeArray.type, storeId: revoked.storeId) |
|
|
|
|
} |
|
|
|
|
fileprivate func _syncRevoke(_ revokeArrays: [ObjectIdentifierArray]) async { |
|
|
|
|
for revokeArray in revokeArrays { |
|
|
|
|
for revoked in revokeArray.items { |
|
|
|
|
await self.synchronizationRevoke(id: revoked.modelId, type: revokeArray.type, storeId: revoked.storeId) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -752,12 +750,10 @@ public class StoreCenter { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Adds or updates an instance into the store |
|
|
|
|
func synchronizationAddOrUpdate<T: SyncedStorable>(_ instance: T, storeId: String?, shared: Bool) { |
|
|
|
|
func synchronizationAddOrUpdate<T: SyncedStorable>(_ instance: T, storeId: String?, shared: Bool) async { |
|
|
|
|
let hasAlreadyBeenDeleted: Bool = self._hasAlreadyBeenDeleted(instance) |
|
|
|
|
if !hasAlreadyBeenDeleted { |
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
self._store(id: storeId).addOrUpdateIfNewer(instance, shared: shared) |
|
|
|
|
} |
|
|
|
|
await self._store(id: storeId).addOrUpdateIfNewer(instance, shared: shared) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|