Skip to content

Commit

Permalink
Refactored initialization of "DatabaseOpenHelperFactory"
Browse files Browse the repository at this point in the history
Moved call to "asCacheControlled" for singleton instance of "DatabaseOpenHelperFactory" from "DatabaseModule.provideInternalCryptomatorDatabase" to new binding "DatabaseModule.provideOpenHelperFactory" to prevent unnecessary duplicate invocations

*This commit is related to issue #529 [1]*

[1] #529
  • Loading branch information
JaniruTEC committed Sep 25, 2024
1 parent 5588563 commit df6c32b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions data/src/main/java/org/cryptomator/data/db/DatabaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper
import org.cryptomator.data.db.SQLiteCacheControl.asCacheControlled
import org.cryptomator.data.db.migrations.legacy.Upgrade10To11
import org.cryptomator.data.db.migrations.legacy.Upgrade11To12
Expand Down Expand Up @@ -57,7 +58,7 @@ class DatabaseModule {
context: Context, //
@DbInternal migrations: Array<Migration>, //
@DbInternal dbTemplateStreamCallable: Callable<InputStream>, //
openHelperFactory: DatabaseOpenHelperFactory, //
@DbInternal openHelperFactory: SupportSQLiteOpenHelper.Factory, //
@DbInternal databaseName: String, //
): CryptomatorDatabase {
LOG.i("Building database (target version: %s)", CRYPTOMATOR_DATABASE_VERSION)
Expand All @@ -66,7 +67,7 @@ class DatabaseModule {
.createFromInputStream(dbTemplateStreamCallable) //
.addMigrations(*migrations) //
.addCallback(DatabaseCallback) //
.openHelperFactory(openHelperFactory.asCacheControlled()) //
.openHelperFactory(openHelperFactory) //
.setJournalMode(RoomDatabase.JournalMode.TRUNCATE) //
.fallbackToDestructiveMigrationFrom(0) //
.build() //Fails if no migration is found (especially when downgrading)
Expand Down Expand Up @@ -96,6 +97,13 @@ class DatabaseModule {
return templateFactory.create().templateFile()
}

@Singleton
@Provides
@DbInternal
internal fun provideOpenHelperFactory(openHelperFactory: DatabaseOpenHelperFactory): SupportSQLiteOpenHelper.Factory {
return openHelperFactory.asCacheControlled()
}

@Singleton
@Provides
@DbInternal
Expand Down

0 comments on commit df6c32b

Please sign in to comment.