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

Stats storages and crash in Aggregate mode #421

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-permission
android:requiredFeature="@string/ark_file_picker_pick"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for fixing a side effect when files access permission toggle was disabled, caused by this commit: c7d14c1

android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ class TagLabeledNStorage(
override suspend fun init() {
val storage = locateStorage()
if (storage?.exists() == true) {
val json = Json.decodeFromStream<JsonTagLabeledN>(storage.inputStream())
tagLabeledAmount.putAll(json.data)
try {
val json = Json.decodeFromStream<JsonTagLabeledN>(
storage.inputStream()
)
tagLabeledAmount.putAll(json.data)
} catch (exception: Exception) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that just logging the exception can be harmful for the storage. We can have 2 kinds of exception here:

  1. Exception during decoding the storage, i.e. reading from disk.
  2. An unlikely problem during putAll.

In either case, the tagLabeledAmount mapping is incorrect. When new stats appear, the will be written to the disk, but only part of the original storage will be written. E.g. if we have 5 entries in the storage, we read 2 of them and then we have an exception. We continue execution with 2/5 entries. Then new entry is coming, so we write 3/6 to the disk. This means we lose some entries in case of the exception.

Stats storage is not that important comparing to tags or scores, but it enhances UX by sorting tags in last-used order. We should avoid losing this data if possible.

Timber.e("TagLabeledNStorage.init exception: " + exception.message)
}
} else {
index.allIds()
.associateWith { tagsStorage.getTags(it) }
Expand Down
Loading