Commit 53ef74d7 authored by Mygod's avatar Mygod

Reduce double persisting panics

parent 045255d4
...@@ -55,7 +55,7 @@ class TrafficMonitor(statFile: File) { ...@@ -55,7 +55,7 @@ class TrafficMonitor(statFile: File) {
var out = TrafficStats() var out = TrafficStats()
private var timestampLast = 0L private var timestampLast = 0L
private var dirty = false private var dirty = false
private var persisted = false private var persisted: TrafficStats? = null
fun requestUpdate(): Pair<TrafficStats, Boolean> { fun requestUpdate(): Pair<TrafficStats, Boolean> {
val now = SystemClock.elapsedRealtime() val now = SystemClock.elapsedRealtime()
...@@ -85,8 +85,9 @@ class TrafficMonitor(statFile: File) { ...@@ -85,8 +85,9 @@ class TrafficMonitor(statFile: File) {
} }
fun persistStats(id: Long) { fun persistStats(id: Long) {
check(!persisted) { "Double persisting?" } val current = current
persisted = true check(persisted == null || persisted == current) { "Data loss occurred" }
persisted = current
try { try {
// profile may have host, etc. modified and thus a re-fetch is necessary (possible race condition) // profile may have host, etc. modified and thus a re-fetch is necessary (possible race condition)
val profile = ProfileManager.getProfile(id) ?: return val profile = ProfileManager.getProfile(id) ?: return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment