Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reconcileAndLocalSaveOperationSink get overwritten #755

Closed
ruiguoamz opened this issue Sep 4, 2020 · 2 comments
Closed

reconcileAndLocalSaveOperationSink get overwritten #755

ruiguoamz opened this issue Sep 4, 2020 · 2 comments
Assignees
Labels
bug Something isn't working datastore Issues related to the DataStore category pending-release Code has been merged but pending release Code has been merged but pending release

Comments

@ruiguoamz
Copy link
Contributor

Describe the bug
In AWSModelReconciliationQueue class:

func enqueue(_ remoteModel: MutationSync<AnyModel>) {
    let reconcileOp = ReconcileAndLocalSaveOperation(remoteModel: remoteModel,
                                                     storageAdapter: storageAdapter)
    reconcileAndLocalSaveOperationSink = reconcileOp.publisher.sink(receiveCompletion: { error in
        self.modelReconciliationQueueSubject.send(completion: error)
    }, receiveValue: { mutationEvent in
        self.modelReconciliationQueueSubject.send(.mutationEvent(mutationEvent))
    })
    reconcileAndSaveQueue.addOperation(reconcileOp)
}

whenever comes a remoteModel, it creates a reconcileOp and subscribes to the reconcileOp.publisher. But reconcileAndLocalSaveOperationSink will keep being replaced by newer reconcileOp.publisher.sink() and cause an issue to receive only one mutationEvent.

Related customer issue: #598

Expected behavior

  • There should be a reconcileAndLocalSaveOperationSink that is able to receive every mutationEvent emitted by reconcileAndLocalSaveOperation.publisher
  • Or have a reconcileAndLocalSaveOperationSink for each reconcileAndLocalSaveOperation.
@ruiguoamz ruiguoamz added bug Something isn't working datastore Issues related to the DataStore category labels Sep 4, 2020
@lawmicha
Copy link
Contributor

lawmicha commented Sep 4, 2020

reproduce this with unit test that will fail, and then apply fix to fix unit test

@lawmicha
Copy link
Contributor

lawmicha commented Sep 4, 2020

func enqueue(_ remoteModel: MutationSync<AnyModel>) {
        let reconcileOp = ReconcileAndLocalSaveOperation(remoteModel: remoteModel,
                                                         storageAdapter: storageAdapter)
        var reconcileAndLocalSaveOperationSink: AnyCancellable?
        reconcileAndLocalSaveOperationSink = reconcileOp.publisher.sink(receiveCompletion: { error in
            self.modelReconciliationQueueSubject.send(completion: error)
            self.reconcileAndLocalSaveOperationSinks.remove(reconcileAndLocalSaveOperationSink)
        }, receiveValue: { mutationEvent in
            self.modelReconciliationQueueSubject.send(.mutationEvent(mutationEvent))
        })
        reconcileAndLocalSaveOperationSinks.insert(reconcileAndLocalSaveOperationSink)
        reconcileAndSaveQueue.addOperation(reconcileOp)
    }

@wooj2 wooj2 added the pending-release Code has been merged but pending release Code has been merged but pending release label Sep 4, 2020
@wooj2 wooj2 closed this as completed Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datastore Issues related to the DataStore category pending-release Code has been merged but pending release Code has been merged but pending release
Projects
None yet
Development

No branches or pull requests

3 participants