Revert "No more main thread SQL"

This reverts commit 4de891b459.

Async writes are a bad idea.
This commit is contained in:
Mygod
2019-02-02 02:48:08 +08:00
parent bf697dafb1
commit 194ef92de3
5 changed files with 11 additions and 27 deletions

View File

@@ -10,10 +10,6 @@ import be.mygod.vpnhotspot.util.Event2
import be.mygod.vpnhotspot.util.RootSession
import be.mygod.vpnhotspot.util.parseNumericAddress
import be.mygod.vpnhotspot.widget.SmartSnackbar
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import timber.log.Timber
import java.net.InetAddress
import java.util.concurrent.TimeUnit
@@ -29,9 +25,7 @@ object TrafficRecorder {
fun register(ip: InetAddress, downstream: String, mac: Long) {
val record = TrafficRecord(mac = mac, ip = ip, downstream = downstream)
GlobalScope.launch(Dispatchers.Main, CoroutineStart.UNDISPATCHED) {
AppDatabase.instance.trafficRecordDao.insert(record)
}
AppDatabase.instance.trafficRecordDao.insert(record)
synchronized(this) {
DebugHelper.log(TAG, "Registering $ip%$downstream")
check(records.put(Pair(ip, downstream), record) == null)
@@ -123,9 +117,7 @@ object TrafficRecorder {
check(record.sentBytes >= 0)
check(record.receivedPackets >= 0)
check(record.receivedBytes >= 0)
GlobalScope.launch(Dispatchers.Main, CoroutineStart.UNDISPATCHED) {
AppDatabase.instance.trafficRecordDao.insert(record)
}
AppDatabase.instance.trafficRecordDao.insert(record)
}
foregroundListeners(records.values, oldRecords)
}