aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Borg <jakob@kastelo.net>2023-12-04 09:24:10 +0100
committerGitHub <noreply@github.com>2023-12-04 09:24:10 +0100
commit1625b448928038689addf2c559a80cc89a21c12c (patch)
tree4fec6f8afc43c5d86c937d0d5e30e652400338c5
parentd51760f410577d926601a14d6b8d4c944dfc4be7 (diff)
downloadsyncthing-1625b448928038689addf2c559a80cc89a21c12c.tar.gz
syncthing-1625b448928038689addf2c559a80cc89a21c12c.zip
lib/model: Improve LastSeen handling (#9256)
LastSeen for a device was only updated when they connected. This now updates it when they disconnect, so that we remember the last time we actually saw them. When asking the API for current stats, currently connected devices get a last seen value of the current time.
-rw-r--r--lib/model/model.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/model/model.go b/lib/model/model.go
index 64475468d..4cc94238c 100644
--- a/lib/model/model.go
+++ b/lib/model/model.go
@@ -817,6 +817,11 @@ func (m *model) DeviceStatistics() (map[protocol.DeviceID]stats.DeviceStatistics
if err != nil {
return nil, err
}
+ if len(m.deviceConnIDs[id]) > 0 {
+ // If a device is currently connected, we can see them right
+ // now.
+ stats.LastSeen = time.Now().Truncate(time.Second)
+ }
res[id] = stats
}
return res, nil
@@ -2483,6 +2488,7 @@ func (m *model) deviceWasSeen(deviceID protocol.DeviceID) {
func (m *model) deviceDidCloseFRLocked(deviceID protocol.DeviceID, duration time.Duration) {
if sr, ok := m.deviceStatRefs[deviceID]; ok {
_ = sr.LastConnectionDuration(duration)
+ _ = sr.WasSeen()
}
}