Repository navigation
fix: sort dispatches by published date instead of insertion timestamp - #11
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
Fixes the dispatch sorting issue where old March 2024 dispatches appeared first instead of current October 2025 dispatches. The root cause was sorting by database insertion timestamp rather than the dispatch's actual published date. Since all 635 dispatches are updated together by the collector, they shared the same insertion timestamp despite different publication dates.
Key Changes:
- Modified dispatch query to sort by JSON-extracted
publishedfield instead of insertiontimestamp - Added comprehensive troubleshooting documentation for backend data collection issues
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/database.py | Updated get_latest_dispatches() to sort by json_extract(data, '$.published') instead of timestamp |
| docs/README.md | Added navigation links to new BACKEND_DATA_REFRESH.md documentation |
| docs/BACKEND_DATA_REFRESH.md | New troubleshooting guide for backend data collection, freshness verification, and collector status |
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.
Problem
The
/api/dispatchesendpoint was returning dispatches sorted by database insertion timestamp instead of by the dispatch's actual published date. This caused old March 2024 dispatches to appear first even though current October 2025 dispatches existed in the database.Root Cause
The
get_latest_dispatches()method insrc/database.pywas using:This sorts by when the row was inserted into the database, not when the dispatch was actually published. Since the collector updates all 635 dispatches together, they all have the same recent database timestamp despite containing data from different historical dates.
Solution
Changed the query to sort by the dispatch's published date from the JSON data:
Now dispatches are correctly sorted by their publication date, with newest first.
Changes
get_latest_dispatches()to sort byjson_extract(data, '$.published')instead oftimestampTesting
✅ Verified the SQL query returns October 2025 dispatches first:
✅ Collector is running every 5 minutes and collecting 635 current dispatches
✅ Upstream Hell Divers 2 API is online and providing fresh data
Impact