Skip to content

Commit 8893be2

Browse files
authored
Move local storage cleanup off the main thread (#6905)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1157893581871903/task/1211520118539805?focus=true ### Description Move the local storage cleanup to the io dispatcher
1 parent 3649b32 commit 8893be2

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

app/src/main/java/com/duckduckgo/app/browser/weblocalstorage/WebLocalStorageManager.kt

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,41 +57,43 @@ class DuckDuckGoWebLocalStorageManager @Inject constructor(
5757
private var matchingRegex = emptyList<String>()
5858

5959
override fun clearWebLocalStorage() = runBlocking {
60-
val settings = androidBrowserConfigFeature.webLocalStorage().getSettings()
61-
val webLocalStorageSettings = webLocalStorageSettingsJsonParser.parseJson(settings)
60+
withContext(dispatcherProvider.io()) {
61+
val settings = androidBrowserConfigFeature.webLocalStorage().getSettings()
62+
val webLocalStorageSettings = webLocalStorageSettingsJsonParser.parseJson(settings)
6263

63-
val fireproofedDomains = if (androidBrowserConfigFeature.fireproofedWebLocalStorage().isEnabled()) {
64-
withContext(dispatcherProvider.io()) {
65-
fireproofWebsiteRepository.fireproofWebsitesSync().map { it.domain }
64+
val fireproofedDomains = if (androidBrowserConfigFeature.fireproofedWebLocalStorage().isEnabled()) {
65+
withContext(dispatcherProvider.io()) {
66+
fireproofWebsiteRepository.fireproofWebsitesSync().map { it.domain }
67+
}
68+
} else {
69+
emptyList()
6670
}
67-
} else {
68-
emptyList()
69-
}
7071

71-
domains = webLocalStorageSettings.domains.list + fireproofedDomains
72-
keysToDelete = webLocalStorageSettings.keysToDelete.list
73-
matchingRegex = webLocalStorageSettings.matchingRegex.list
72+
domains = webLocalStorageSettings.domains.list + fireproofedDomains
73+
keysToDelete = webLocalStorageSettings.keysToDelete.list
74+
matchingRegex = webLocalStorageSettings.matchingRegex.list
7475

75-
logcat { "WebLocalStorageManager: Allowed domains: $domains" }
76-
logcat { "WebLocalStorageManager: Keys to delete: $keysToDelete" }
77-
logcat { "WebLocalStorageManager: Matching regex: $matchingRegex" }
76+
logcat { "WebLocalStorageManager: Allowed domains: $domains" }
77+
logcat { "WebLocalStorageManager: Keys to delete: $keysToDelete" }
78+
logcat { "WebLocalStorageManager: Matching regex: $matchingRegex" }
7879

79-
val db = databaseProvider.get()
80-
db.iterator().use { iterator ->
81-
iterator.seekToFirst()
80+
val db = databaseProvider.get()
81+
db.iterator().use { iterator ->
82+
iterator.seekToFirst()
8283

83-
while (iterator.hasNext()) {
84-
val entry = iterator.next()
85-
val key = String(entry.key, StandardCharsets.UTF_8)
84+
while (iterator.hasNext()) {
85+
val entry = iterator.next()
86+
val key = String(entry.key, StandardCharsets.UTF_8)
8687

87-
val domainForMatchingAllowedKey = getDomainForMatchingAllowedKey(key)
88-
if (domainForMatchingAllowedKey == null) {
89-
db.delete(entry.key)
90-
logcat { "WebLocalStorageManager: Deleted key: $key" }
91-
} else if (settingsDataStore.clearDuckAiData && domainForMatchingAllowedKey == DUCKDUCKGO_DOMAIN) {
92-
if (keysToDelete.any { key.endsWith(it) }) {
88+
val domainForMatchingAllowedKey = getDomainForMatchingAllowedKey(key)
89+
if (domainForMatchingAllowedKey == null) {
9390
db.delete(entry.key)
9491
logcat { "WebLocalStorageManager: Deleted key: $key" }
92+
} else if (settingsDataStore.clearDuckAiData && domainForMatchingAllowedKey == DUCKDUCKGO_DOMAIN) {
93+
if (keysToDelete.any { key.endsWith(it) }) {
94+
db.delete(entry.key)
95+
logcat { "WebLocalStorageManager: Deleted key: $key" }
96+
}
9597
}
9698
}
9799
}

0 commit comments

Comments
 (0)