Add play session ingest for game time tracking#3155
Open
tmgast wants to merge 3 commits intorommapp:masterfrom
Open
Add play session ingest for game time tracking#3155tmgast wants to merge 3 commits intorommapp:masterfrom
tmgast wants to merge 3 commits intorommapp:masterfrom
Conversation
Backend API for collecting and querying play sessions, modeled after the Argosy session data format. Clients submit batches per device, recording both the session window and screen-on time.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds backend support for ingesting and querying per-user game play sessions (modeled after Argosy session data) to enable game-time tracking and “last played” updates.
Changes:
- Introduces
PlaySessionmodel + Alembic migration with indexes for common query patterns and dedup identity. - Adds
/api/play-sessionsendpoints for batch ingest, querying, and delete; updatesrom_user.last_playedanddevice.last_seen. - Adds comprehensive endpoint tests covering ingest validation, dedup, isolation, and query filtering.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/tests/endpoints/test_play_sessions.py | New test suite covering ingest/query/delete behaviors and edge cases. |
| backend/tests/conftest.py | Ensures PlaySession rows are cleared between tests. |
| backend/models/user.py | Adds User.play_sessions relationship for cascading deletes/orphans. |
| backend/models/play_session.py | New SQLAlchemy model for persisted play sessions with indexes/uniqueness. |
| backend/main.py | Registers the new play-sessions router. |
| backend/handler/database/play_sessions_handler.py | New DB handler for CRUD/query/dedup support. |
| backend/handler/database/init.py | Exposes db_play_session_handler singleton. |
| backend/endpoints/responses/play_session.py | Adds response/request schemas for play session APIs. |
| backend/endpoints/play_sessions.py | Implements POST ingest (batch + dedup), GET query, DELETE by id. |
| backend/alembic/versions/0073_play_sessions.py | Creates the play_sessions table and indexes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace per-item add_session with add_sessions using add_all. No fallback on IntegrityError -- duplicate concurrent submissions are the client's responsibility.
gantoine
approved these changes
Mar 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds play session tracking modeled after the Argosy session data format. Clients submit batches of play sessions per device, recording when and how long games were played. Sessions track both the time window (
start_time/end_time) and screen-on time (duration_ms), which may differ due to device suspension or backgrounding.Known Gaps
New Model
PlaySession
idint(PK)user_idint(FK)device_idstr?(FK)rom_idint?(FK)save_slotstr?start_timedatetimeend_timedatetimeduration_msbigintIndexes:
(user_id, rom_id),(user_id, start_time), unique on(user_id, device_id, rom_id, start_time)New API Endpoints
POST
/api/play-sessionsdevice_idorrom_idresolves to NULL rather than rejecting(user_id, device_id, rom_id, start_time)via batched queryrom_user.last_playedanddevice.last_seenon successPer-item
statusis one ofcreated,duplicate, orerror.GET
/api/play-sessionsstart_afterorend_beforeis set, the count limit is bypassed for stats use casesrom_idint?device_idstr?start_afterdatetime?end_beforedatetime?limitintoffsetintDELETE
/api/play-sessions/{session_id}Database Changes
0073_play_sessions.pyChecklist