Skip to content

✨ Add GET /api/v1/session and deprecate session heartbeat#78

Open
yuler wants to merge 1 commit into
mainfrom
core-heartbeat
Open

✨ Add GET /api/v1/session and deprecate session heartbeat#78
yuler wants to merge 1 commit into
mainfrom
core-heartbeat

Conversation

@yuler
Copy link
Copy Markdown
Owner

@yuler yuler commented May 20, 2026

Summary

  • Add GET /api/v1/session as the canonical session read endpoint (updates last_active_at, returns identity JSON)
  • Extract shared SessionIdentity concern; keep GET /api/v1/session/heartbeat as a deprecated alias for API v2 removal
  • Migrate desktop auth polling to GET /api/v1/session and rename heartbeat helpers to session sync

Test plan

  • bin/rails test for sessions_controller_test and heartbeats_controller_test (9 runs, 0 failures)
  • Desktop: log in, confirm session stays valid and user info syncs after ~2 minutes

Made with Cursor

Adds GET /api/v1/session as the new session identity endpoint. Refactors
session identity logic into a SessionIdentity concern and updates the
desktop client to use the new endpoint with renamed sessionSync functions.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request renames the heartbeat mechanism to session sync across the desktop application and backend. It introduces a new GET /api/v1/session endpoint, refactors shared logic into a SessionIdentity concern, and deprecates the legacy heartbeat route. Feedback suggests optimizing the session timestamp update by using touch instead of update! to bypass full ActiveRecord lifecycles and using safe navigation to handle potentially nil sessions.


private
def render_session_identity
Current.session.update!(last_active_at: Time.current)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using update! for a heartbeat or session sync is inefficient because it triggers the full ActiveRecord lifecycle, including validations and callbacks. For high-frequency updates of a single timestamp, touch is significantly more performant as it executes a targeted SQL UPDATE. Additionally, using safe navigation (&.) is a safer practice to prevent potential NoMethodError if Current.session is unexpectedly nil, maintaining consistency with the destroy action in SessionsController.

      Current.session&.touch(:last_active_at)

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.

1 participant