Skip to content

Commit

Permalink
revert some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ruiguoamz committed Aug 25, 2020
1 parent 5fcc641 commit 7db15ce
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
Amplify.Hub.removeListener(token)
}
}

let payloadOfOutboxStatus = HubPayload(eventName: HubPayload.EventName.DataStore.outboxStatusChanged)
Amplify.Hub.dispatch(to: .dataStore, payload: payloadOfOutboxStatus)

let payload = HubPayload(eventName: HubPayload.EventName.DataStore.ready)
Amplify.Hub.dispatch(to: .dataStore, payload: payload)
}

func reinitStorageEngineIfNeeded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,42 +55,6 @@ final class InitialSyncOperation: AsynchronousOperation {
log.info("Beginning sync for \(modelType.modelName)")
let lastSyncTime = getLastSyncTime()
query(lastSyncTime: lastSyncTime)

var modelSyncedPayload = ModelSyncedPayload()
modelSyncedPayload.modelName = modelType.modelName
modelSyncedPayload.isFullSync = lastSyncTime == 0 ? true : false
modelSyncedPayload.isDeltaSync = !modelSyncedPayload.isFullSync

guard let reconciliationQueue = reconciliationQueue else {
return
}

_ = reconciliationQueue.publisher.sink(
receiveCompletion: { result in
print(result)
}, receiveValue: { result in
print(result)
switch result {
case .initialized, .started, .paused:
print(result)
case .mutationEvent(let mutationEvent):
modelSyncedPayload.modelName = mutationEvent.modelName
switch mutationEvent.mutationType {
case "create":
modelSyncedPayload.createCount += 1
case "update":
modelSyncedPayload.updateCount += 1
case "delete":
modelSyncedPayload.deleteCount += 1
default:
print(result)
}
}
})

let payload = HubPayload(eventName: HubPayload.EventName.DataStore.modelSynced,
data: modelSyncedPayload)
Amplify.Hub.dispatch(to: .dataStore, payload: payload)
}

private func getLastSyncTime() -> Int? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ class SyncMutationToCloudOperation: Operation {
if let reachability = api as? APICategoryReachabilityBehavior {
do {
networkReachabilityPublisher = try reachability.reachabilityPublisher(for: request.apiName)

} catch {
log.error("\(#function): Unable to listen on reachability: \(error)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ class RemoteSyncEngine: RemoteSyncEngineBehavior {
}
}

// _ = self.networkReachabilityPublisher?.sink(receiveValue: { value in
// let payload = HubPayload(eventName: HubPayload.EventName.DataStore.networkStatusChanged,
// data: value.isOnline)
// Amplify.Hub.dispatch(to: .dataStore, payload: payload)
// })

self.outgoingMutationQueueSink = self.outgoingMutationQueue.publisher.sink { mutationEvent in
self.remoteSyncTopicPublisher.send(.mutationEvent(mutationEvent))
}
Expand Down Expand Up @@ -331,9 +325,6 @@ class RemoteSyncEngine: RemoteSyncEngineBehavior {
Amplify.Hub.dispatch(to: .dataStore,
payload: HubPayload(eventName: HubPayload.EventName.DataStore.syncStarted))

Amplify.Hub.dispatch(to: .dataStore,
payload: HubPayload(eventName: HubPayload.EventName.DataStore.ready))

remoteSyncTopicPublisher.send(.syncStarted)
stateMachine.notify(action: .notifiedSyncStarted)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class AWSIncomingEventReconciliationQueue: IncomingEventReconciliationQueu
}
reconciliationQueues[modelName] = queue
let modelReconciliationQueueSink = queue.publisher.sink(receiveCompletion: onReceiveCompletion(completed:),
receiveValue: onReceiveValue(receiveValue:))
receiveValue: onReceiveValue(receiveValue:))
modelReconciliationQueueSinks[modelName] = modelReconciliationQueueSink
}
}
Expand Down Expand Up @@ -148,6 +148,3 @@ extension AWSIncomingEventReconciliationQueue: Resettable {
}

}

@available(iOS 13.0, *)
extension AWSIncomingEventReconciliationQueue: DefaultLogger { }
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ final class AWSModelReconciliationQueue: ModelReconciliationQueue {
private func receiveCompletion(_ completion: Subscribers.Completion<DataStoreError>) {
switch completion {
case .finished:
log.info("receivedCompletion: finished")
modelReconciliationQueueSubject.send(completion: .finished)
case .failure(let dataStoreError):
log.error("receiveCompletion: error: \(dataStoreError)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation {
self.respond(to: newState)
}
}

}

override func main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MockAWSInitialSyncOrchestrator: InitialSyncOrchestrator {
storageAdapter: storageAdapter)
}

typealias SyncOperationResult = Result<ModelSyncPayload?, DataStoreError>
typealias SyncOperationResult = Result<ModelSyncedPayload?, DataStoreError>
typealias SyncOperationResultHandler = (SyncOperationResult) -> Void

private static var instance: MockAWSInitialSyncOrchestrator?
Expand All @@ -43,7 +43,7 @@ class MockAWSInitialSyncOrchestrator: InitialSyncOrchestrator {
}

func sync(completion: @escaping SyncOperationResultHandler) {
let response = MockAWSInitialSyncOrchestrator.mockedResponse ?? .successfulVoid
let response = MockAWSInitialSyncOrchestrator.mockedResponse ?? .success(nil)
completion(response)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct NoOpInitialSyncOrchestrator: InitialSyncOrchestrator {
NoOpInitialSyncOrchestrator()
}

func sync(completion: @escaping (Result<Void, DataStoreError>) -> Void) {
completion(Result.successfulVoid)
func sync(completion: @escaping (Result<ModelSyncedPayload?, DataStoreError>) -> Void) {
completion(Result.success(nil))
}
}

0 comments on commit 7db15ce

Please sign in to comment.