package service import "time" // TouchLastSeen 更新用户最近活跃时间(在线统计)。 // SQL 条件限频:每用户每 60 秒最多真正写一次,其余为命中 0 行的空更新; // 调用方以 goroutine 异步触发,不增加请求链路延迟。 func (s *AuthService) TouchLastSeen(userID uint) { threshold := time.Now().Add(-time.Minute) _ = s.db.Exec( `UPDATE users SET last_seen_at = NOW() WHERE id = ? AND (last_seen_at IS NULL OR last_seen_at < ?)`, userID, threshold, ).Error }