element-hq / element-hq/element-android

[SDK] Offer several session cache strategies

Open
#3,045 0 comments 1 reaction 0 assignees View on GitHub
matrix-sdk Z-resource:database
Dominant language
Kotlin
Stars
3.7k
Forks
917
PR merge metrics
No merged PRs in 30d

Description

We know that when the database is getting bigger, the queries become slower, and so the whole application seems less responsive.

The current strategy is to keep every Events received from the server, even in case of gappy sync, for a better user experience and to limit the network data consumption. We also periodically [cleanup the database](https://github.com/vector-im/element-android/blob/develop/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/DatabaseCleaner.kt) if necessary by deleting the oldest events, to avoid the database from growing indefinitely.

In some cases the client of the SDK would like to ensure that the database is as small as possible, to keep the best possible performance.

So the MatrixConfiguration could provide a new enum `SessionCacheStrategy`, with 3 possible values:
- `KeepAll`: database is never cleaned up. This provide the best user experience. A message he has seen on his device will always be there. Note that the message can still be hidden to the user in case of gappy sync, since in EA timelines we do not display events before the gap. But once the gap is filled, there is no need to download the previous Events again. So network data consumption is optimized.
- `Automatic`: the SDK will choose the best strategy. This can be equivalent to what we have today, but in case of small account, it could be the same than `KeepAll` and in case of big account, the same as `DeleteAll`. This could be the default value. Also the SDK can consider the device capability (free disk memory for instance, network quality, etc.)
- `DeleteAll`: in case of gappy sync, all the previous chunk are deleted. The database will be as small as possible, but the data will have to be downloaded more often.

In Element Android, this strategy choice could be exposed to the user as an advanced setting.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.