Skip to content

Commit 5f6b47f

Browse files
committed
use dedicated updateTraffic to avoid overwriting ping test results
1 parent edf26a2 commit 5f6b47f

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

app/src/main/java/io/nekohasekai/sagernet/bg/proto/TrafficLooper.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TrafficLooper
3131
val item = idMap[ent.id] ?: return@forEach
3232
ent.rx = item.rx
3333
ent.tx = item.tx
34-
ProfileManager.updateProfile(ent) // update DB
34+
ProfileManager.updateTraffic(ent.id, ent.rx, ent.tx)
3535
traffic[ent.id] = TrafficData(
3636
id = ent.id,
3737
rx = ent.rx,
@@ -67,7 +67,7 @@ class TrafficLooper
6767
it.rx = rx
6868
it.tx = tx
6969
runOnDefaultDispatcher {
70-
ProfileManager.updateProfile(it) // update DB
70+
ProfileManager.updateTraffic(it.id, it.rx, it.tx)
7171
}
7272
}
7373
}
@@ -184,4 +184,4 @@ class TrafficLooper
184184
delay(delayMs)
185185
}
186186
}
187-
}
187+
}

app/src/main/java/io/nekohasekai/sagernet/database/ProfileManager.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ object ProfileManager {
9797
}
9898
}
9999

100+
suspend fun updateTraffic(profileId: Long, rx: Long, tx: Long) {
101+
SagerDatabase.proxyDao.updateTraffic(profileId, rx, tx)
102+
}
103+
100104
suspend fun deleteProfile2(groupId: Long, profileId: Long) {
101105
if (SagerDatabase.proxyDao.deleteById(profileId) == 0) return
102106
if (DataStore.selectedProxy == profileId) {

app/src/main/java/io/nekohasekai/sagernet/database/ProxyEntity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ data class ProxyEntity(
605605
@Update
606606
fun updateProxy(proxies: List<ProxyEntity>): Int
607607

608+
@Query("UPDATE proxy_entities SET rx = :rx, tx = :tx WHERE id = :proxyId")
609+
fun updateTraffic(proxyId: Long, rx: Long, tx: Long): Int
610+
608611
@Insert
609612
fun addProxy(proxy: ProxyEntity): Long
610613

0 commit comments

Comments
 (0)