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.
This commit is contained in:
Jakob Borg 2023-12-04 09:24:10 +01:00 committed by GitHub
parent d51760f410
commit 1625b44892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()
}
}