Skip to content

Commit

Permalink
On second thought, we can just let the OpenHelper get gc'd
Browse files Browse the repository at this point in the history
  • Loading branch information
daytime-em committed Aug 23, 2024
1 parent e9539df commit ee1489d
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,8 @@ internal class CacheDatastore(
@Throws(IOException::class)
private fun awaitDbHelper(): DbHelper {
// inner function closes db if the calling thread was interrupted
fun closeAndCancelIfInterrupted(dbHelper: DbHelper?) {
fun cancelIfInterrupted() {
if (Thread.interrupted()) {
dbHelper?.close()
throw CancellationException("open interrupted")
}
}
Expand All @@ -381,20 +380,21 @@ internal class CacheDatastore(
fun doOpen(): DbHelper {
// todo - we should also consider getting our cacheQuota here, that will take a long time
// so maybe do it async & only consider the cache quota once we have it(..?)
closeAndCancelIfInterrupted(null)

cancelIfInterrupted()
clearTempFiles()
closeAndCancelIfInterrupted(null)
cancelIfInterrupted()
ensureDirs()

val helper = DbHelper(context, indexDbDir())
closeAndCancelIfInterrupted(helper)
cancelIfInterrupted()

// Do some db maintenance when we start up, in case shutdown wasn't clean
helper.writableDatabase.use { db ->
doEvictByLru(db)
}

closeAndCancelIfInterrupted(helper)
cancelIfInterrupted()
return helper
}

Expand Down

0 comments on commit ee1489d

Please sign in to comment.