[db] update repo cache right after new repo got added

so we can use the new repo right away without waiting for DB to inform us about change. This is important if we want to show list of apps of a repo right after adding it.
This commit is contained in:
Torsten Grote
2023-09-21 17:46:49 +02:00
committed by Michael Pöhn
parent 4bd033e6a7
commit 51d43f9004
2 changed files with 10 additions and 3 deletions

View File

@@ -143,7 +143,13 @@ public class RepoManager @JvmOverloads constructor(
@AnyThread
public fun addFetchedRepository() {
GlobalScope.launch(coroutineContext) {
repoAdder.addFetchedRepository()
val addedRepo = repoAdder.addFetchedRepository()
// if repo was added, update state right away, so it becomes available asap
if (addedRepo != null) withContext(Dispatchers.Main) {
_repositoriesState.value = _repositoriesState.value.toMutableList().apply {
add(addedRepo)
}
}
}
}

View File

@@ -217,9 +217,9 @@ internal class RepoAdder(
}
@WorkerThread
internal fun addFetchedRepository() {
internal fun addFetchedRepository(): Repository? {
// prevent double calls (e.g. caused by double tapping a UI button)
if (addRepoState.compareAndSet(Adding, Adding)) return
if (addRepoState.compareAndSet(Adding, Adding)) return null
// cancel fetch preview job, so it stops emitting new states
fetchJob?.cancel()
@@ -265,6 +265,7 @@ internal class RepoAdder(
}
}
addRepoState.value = Added(modifiedRepo)
return modifiedRepo
}
internal fun abortAddingRepo() {