awslabs / awslabs/aws-mobile-appsync-sdk-android

AWSAppSyncClient should load records from local db asynchronously

Open
#204 1 comment 0 reactions 0 assignees View on GitHub
bug documentation
Dominant language
Java
Stars
106
Forks
56
PR merge metrics
No merged PRs in 30d

Description

**Problem description**
[Documentation points out a way](https://aws-amplify.github.io/docs/android/api#client-initialization) to create `AWSAppSyncClient` on the main thread. However, internally, when the `AWSAppSyncClient` instance is created, it also creates an instance of `PersistentOfflineMutationManager` which loads the records from db in `fetchPersistentMutationsList()` (and in described case that would happen on the main thread).

This is not a good practice (probably may even lead to a crash), especially that would be a problem if there are many records in db, like happened here #203
https://developer.android.com/training/articles/perf-anr#Avoiding
> Potentially long running operations such as network or database operations, or computationally expensive calculations such as resizing bitmaps should be done in a worker thread (or in the case of databases operations, via an asynchronous request).

**Possible solutions**
1. Either update documentation to say that `AWSAppSyncClient` should be initialized on a background thread
1. Or rework `PersistentOfflineMutationManager` initialization to happen in background

Contributor guide

Open the contributing guide

Research direction

Start by tracing AWSAppSyncClient construction into PersistentOfflineMutationManager and its fetchPersistentMutationsList() call. Compare the documented client initialization guidance with the Android ANR guidance, then verify that the chosen resolution prevents database loading on the main thread or clearly documents the required background initialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, aws, graphql, java
Domain
databases, mobile, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.