✨ Add GET /api/v1/session and deprecate session heartbeat#78
Conversation
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
Summary
GET /api/v1/sessionas the canonical session read endpoint (updateslast_active_at, returns identity JSON)SessionIdentityconcern; keepGET /api/v1/session/heartbeatas a deprecated alias for API v2 removalGET /api/v1/sessionand rename heartbeat helpers to session syncTest plan
bin/rails testforsessions_controller_testandheartbeats_controller_test(9 runs, 0 failures)Made with Cursor