aws-amplify / amplify-swift

A declarative library for application development using cloud services.
Apache License 2.0
447 stars 193 forks source link

Datastore sync reading all over from start on each amplify sync #3841

Open amruth-movano opened 2 weeks ago

amruth-movano commented 2 weeks ago

Describe the bug

Doing appsync in every minute to ensure each min data sync to the datastore and cloud. But it is increasing the read operation count to dynamodb.

Currently, our app has a 2-week caching mechanism, so on login it will fetch 2 weeks of data. But the read count in dynamodb is huge which is not as per the no of rows present in that table. Its almost 10 times per day

Steps To Reproduce

Try Amplify.DataStore.start() after each 1 min and check hits in db

Expected behavior

Amplify should not reread data that is already present in DB, it should only read the delta wrt the current date

Amplify Framework Version

2.35.4

Amplify Categories

DataStore

Dependency manager

Swift PM

Swift version

5.9.2

CLI version

12.11.1

Xcode version

15.0

Relevant log output

-

Is this a regression?

Yes

Regression additional context

No response

Platforms

iOS

OS Version

iOS 17.5.1

Device

iPhone 15 Plus

Specific to simulators

No response

Additional context

No response

tylerjroach commented 2 weeks ago

You can adjust the syncInterval in DataStore configuration as shown here: https://docs.amplify.aws/gen1/swift/build-a-backend/more-features/datastore/conflict-resolution/#custom-configuration-fields

You will also need to check how long your Delta table ttl is set on the service side as well. See Delta sync table time to live (TTL in minutes) in your table Data sources in the AppSync console . Both values may need to be raised to your desired amount.

amruth-movano commented 1 week ago

@tylerjroach Will it only affect datastore reading or for both writing & reading? We need to push as soon as we save to the datastore.

tylerjroach commented 1 week ago

syncInterval - the maximum interval (in seconds) for which the system will continue to perform delta queries. After this interval expires, the system performs a base query to retrieve all data.

This will not slow syncing on model saves. This value is specifically used for when to attempt a delta query vs a full base query.