Skip to content

Commit d808a1a

Browse files
CopilotTomTasche
andcommitted
Remove inaccessible documents from storage to improve performance
Co-authored-by: TomTasche <128734+TomTasche@users.noreply.github.com>
1 parent c404062 commit d808a1a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

app/src/main/java/at/tomtasche/reader/background/RecentDocumentsUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public static Map<String, String> getRecentDocuments(Context context)
2525
Map<String, String> result = new HashMap<String, String>();
2626

2727
JSONArray jsonArray = getRecentDocumentsJson(context);
28+
JSONArray filteredArray = new JSONArray();
29+
boolean hasInaccessibleDocuments = false;
30+
2831
for (int i = 0; i < jsonArray.length(); i++) {
2932
JSONObject document = jsonArray.getJSONObject(i);
3033
String filename = document.getString("filename");
@@ -33,9 +36,17 @@ public static Map<String, String> getRecentDocuments(Context context)
3336
// Only include URIs that are still accessible
3437
if (isUriAccessible(context, Uri.parse(uri))) {
3538
result.put(filename, uri);
39+
filteredArray.put(document);
40+
} else {
41+
hasInaccessibleDocuments = true;
3642
}
3743
}
3844

45+
// Remove inaccessible documents from storage to avoid checking them again
46+
if (hasInaccessibleDocuments) {
47+
saveJson(context, filteredArray);
48+
}
49+
3950
return result;
4051
}
4152

0 commit comments

Comments
 (0)