aws-amplify / aws-amplify/amplify-android

DataStore subscriptionDataProcessed event is dispatched twice

Open
#1,657 0 comments 0 reactions 0 assignees View on GitHub
datastore improvement question
Dominant language
Java
Stars
287
Forks
132
Avg merge
2d 2h
Merged PRs (30d)
45

Description

### Before opening, please confirm:

- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-android/issues?q=is%3Aissue+) and [discussions](https://github.com/aws-amplify/amplify-android/discussions).

### Language and Async Model

Java, Kotlin

### Amplify Categories

DataStore

### Gradle script dependencies

```groovy
// Put output below this line

```

### Environment information

```
# Put output below this line

```

### Please include any relevant guides or documentation you're referencing

_No response_

### Describe the bug

Observed from testing with amplify-flutter.

When a GraphQL subscription event arrives, after processing merge the data into local DB, `subscriptionDataProcessed` event gets dispatched twice via DataStore hub event channel.

It looks like that [this spot](https://github.com/aws-amplify/amplify-android/blob/main/aws-datastore/src/main/java/com/amplifyframework/datastore/syncengine/Merger.java#L115) were executed twice during the merge process following this order:
by 1) [here](https://github.com/aws-amplify/amplify-android/blob/main/aws-datastore/src/main/java/com/amplifyframework/datastore/storage/sqlite/SQLiteStorageAdapter.java#L376) and 2) [here](https://github.com/aws-amplify/amplify-android/blob/main/aws-datastore/src/main/java/com/amplifyframework/datastore/syncengine/VersionRepository.java#L63)

According to the source code and code commends, `subscriptionDataProcessed` event is dispatched on a successful data merge, which should be dispatched only once. Could you confirm if the current behavior is correct?

Additional context: amplify-ios emits a simple event `syncReceived` after the merging process triggered by a GraphQL subscription event. And `syncReceived` event gets dispatched once.

### Reproduction steps (if applicable)

1. Trigger a GraphQL subscription from any valid source
2. Observe `subscriptionDataProcessed` event on DataStore hub

### Code Snippet

```java
// Put your code below this line.

```

### Log output

```
// Put your logs below this line

```

### amplifyconfiguration.json

_No response_

### GraphQL Schema

```graphql
// Put your schema below this line

```

### Additional information and screenshots

_No response_

Contributor guide

Open the contributing guide

Research direction

Read Merger.java around line 115, then trace the two merge paths identified in SQLiteStorageAdapter.java line 376 and VersionRepository.java line 63. Reproduce with a GraphQL subscription and observe the DataStore Hub; done means subscriptionDataProcessed is dispatched once after a successful merge.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.