Prevent main thread queries
This commit is contained in:
@@ -19,7 +19,6 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
.addMigrations(
|
||||
Migration2
|
||||
)
|
||||
.allowMainThreadQueries()
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ data class ClientRecord(@PrimaryKey
|
||||
abstract fun lookupSync(mac: Long): LiveData<ClientRecord>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
protected abstract fun updateInternal(value: ClientRecord): Long
|
||||
fun update(value: ClientRecord) = check(updateInternal(value) == value.mac)
|
||||
protected abstract suspend fun updateInternal(value: ClientRecord): Long
|
||||
suspend fun update(value: ClientRecord) = check(updateInternal(value) == value.mac)
|
||||
|
||||
@Transaction
|
||||
open fun upsert(mac: Long, operation: ClientRecord.() -> Unit) = runBlocking { lookupOrDefault(mac) }.apply {
|
||||
open suspend fun upsert(mac: Long, operation: suspend ClientRecord.() -> Unit) = lookupOrDefault(mac).apply {
|
||||
operation()
|
||||
update(this)
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ data class TrafficRecord(
|
||||
@androidx.room.Dao
|
||||
abstract class Dao {
|
||||
@Insert
|
||||
protected abstract fun insertInternal(value: TrafficRecord): Long
|
||||
fun insert(value: TrafficRecord) {
|
||||
protected abstract suspend fun insertInternal(value: TrafficRecord): Long
|
||||
suspend fun insert(value: TrafficRecord) {
|
||||
check(value.id == null)
|
||||
value.id = insertInternal(value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user