Skip to content

fix: simplify agent state timestamp calculation#3

Merged
SammyLin merged 1 commit into
masterfrom
fix/optimize-agent-state-timestamp
Mar 9, 2026
Merged

fix: simplify agent state timestamp calculation#3
SammyLin merged 1 commit into
masterfrom
fix/optimize-agent-state-timestamp

Conversation

@the3mi
Copy link
Copy Markdown
Collaborator

@the3mi the3mi commented Mar 6, 2026

As suggested in PR #2 review by @juliusv:

In getAgentState you first do secondsAgo := time.Since(latest.modTime).Seconds(), and then you convert it back again. Maybe even cleaner to just return the timestamp to begin with?

Changes

Instead of:

  1. Calculate secondsAgo from modTime
  2. Return secondsAgo
  3. In Collect: time.Now().Unix() - secondsAgo (redundant)

Now:

  1. Return Unix timestamp directly from getAgentState()
  2. Calculate secondsAgo internally only when needed for state logic
  3. In Collect: use timestamp directly (no calculation needed)

This is cleaner and avoids the redundant calculation.

Instead of calculating secondsAgo and converting back to timestamp,
now directly return Unix timestamp from getAgentState().

This is cleaner and avoids the redundant calculation:
  Before: time.Now().Unix() - secondsAgo
  After:  timestamp (direct)
@SammyLin SammyLin merged commit a5fdaf0 into master Mar 9, 2026
3 checks passed
@SammyLin SammyLin deleted the fix/optimize-agent-state-timestamp branch March 9, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants