diff --git a/hscontrol/db/node.go b/hscontrol/db/node.go index b49a6ba3..08b6d233 100644 --- a/hscontrol/db/node.go +++ b/hscontrol/db/node.go @@ -293,12 +293,6 @@ func (hsdb *HSDatabase) DeleteEphemeralNode( }) } -// SetLastSeen sets a node's last seen field indicating that we -// have recently communicating with this node. -func SetLastSeen(tx *gorm.DB, nodeID types.NodeID, lastSeen time.Time) error { - return tx.Model(&types.Node{}).Where("id = ?", nodeID).Update("last_seen", lastSeen).Error -} - // HandleNodeFromAuthPath is called from the OIDC or CLI auth path // with a registrationID to register or reauthenticate a node. // If the node found in the registration cache is not already registered, diff --git a/hscontrol/poll.go b/hscontrol/poll.go index 3802401f..b9088658 100644 --- a/hscontrol/poll.go +++ b/hscontrol/poll.go @@ -9,14 +9,12 @@ import ( "slices" "time" - "github.com/juanfont/headscale/hscontrol/db" "github.com/juanfont/headscale/hscontrol/mapper" "github.com/juanfont/headscale/hscontrol/types" "github.com/juanfont/headscale/hscontrol/util" "github.com/rs/zerolog/log" "github.com/sasha-s/go-deadlock" xslices "golang.org/x/exp/slices" - "gorm.io/gorm" "tailscale.com/net/tsaddr" "tailscale.com/tailcfg" ) @@ -406,15 +404,6 @@ func (h *Headscale) updateNodeOnlineStatus(online bool, node *types.Node) { // lastSeen is only relevant if the node is disconnected. node.LastSeen = &now change.LastSeen = &now - - err := h.db.Write(func(tx *gorm.DB) error { - return db.SetLastSeen(tx, node.ID, *node.LastSeen) - }) - if err != nil { - log.Error().Err(err).Msg("Cannot update node LastSeen") - - return - } } ctx := types.NotifyCtx(context.Background(), "poll-nodeupdate-onlinestatus", node.Hostname) diff --git a/hscontrol/types/node.go b/hscontrol/types/node.go index 6654cefd..151f43cc 100644 --- a/hscontrol/types/node.go +++ b/hscontrol/types/node.go @@ -88,8 +88,11 @@ type Node struct { AuthKeyID *uint64 `sql:"DEFAULT:NULL"` AuthKey *PreAuthKey - LastSeen *time.Time - Expiry *time.Time + Expiry *time.Time + + // LastSeen is when the node was last in contact with + // headscale. It is best effort and not persisted. + LastSeen *time.Time `gorm:"-"` // DEPRECATED: Use the ApprovedRoutes field instead. // TODO(kradalby): remove when ApprovedRoutes is used all over the code.