Move walCheckpoint to RepositoryDao

This commit is contained in:
DerGenaue
2024-10-03 00:52:01 +02:00
committed by Torsten Grote
parent 38ce497525
commit 445f521b1f
3 changed files with 18 additions and 19 deletions

View File

@@ -8,20 +8,10 @@ import androidx.room.Insert
import androidx.room.MapInfo
import androidx.room.OnConflictStrategy.Companion.REPLACE
import androidx.room.Query
import androidx.room.RawQuery
import androidx.sqlite.db.SimpleSQLiteQuery
import androidx.sqlite.db.SupportSQLiteQuery
public interface AppPrefsDao {
public fun getAppPrefs(packageName: String): LiveData<AppPrefs>
public fun update(appPrefs: AppPrefs)
/**
* Force a checkpoint on the SQLite WAL such that the file size gets reduced.
* Blocks until concurrent reads have finished.
* Useful to call after large inserts (repo update)
*/
public fun walCheckpoint()
}
@Dao
@@ -59,11 +49,4 @@ internal interface AppPrefsDaoInt : AppPrefsDao {
@Insert(onConflict = REPLACE)
override fun update(appPrefs: AppPrefs)
override fun walCheckpoint() {
rawCheckpoint((SimpleSQLiteQuery("pragma wal_checkpoint(truncate)")))
}
@RawQuery
fun rawCheckpoint(supportSQLiteQuery: SupportSQLiteQuery): Int
}

View File

@@ -6,9 +6,12 @@ import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy.Companion.REPLACE
import androidx.room.Query
import androidx.room.RawQuery
import androidx.room.RewriteQueriesToDropUnusedColumns
import androidx.room.Transaction
import androidx.room.Update
import androidx.sqlite.db.SimpleSQLiteQuery
import androidx.sqlite.db.SupportSQLiteQuery
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.decodeFromJsonElement
import org.fdroid.database.DbDiffUtils.diffAndUpdateListTable
@@ -87,6 +90,13 @@ public interface RepositoryDao {
* Removes all repos and their preferences.
*/
public fun clearAll()
/**
* Force a checkpoint on the SQLite WAL such that the file size gets reduced.
* Blocks until concurrent reads have finished.
* Useful to call after large inserts (repo update)
*/
public fun walCheckpoint()
}
@Dao
@@ -527,4 +537,10 @@ internal interface RepositoryDaoInt : RepositoryDao {
@Query("SELECT COUNT(*) FROM ${ReleaseChannel.TABLE}")
fun countReleaseChannels(): Int
override fun walCheckpoint() {
rawCheckpoint((SimpleSQLiteQuery("pragma wal_checkpoint(truncate)")))
}
@RawQuery
fun rawCheckpoint(supportSQLiteQuery: SupportSQLiteQuery): Int
}