fix: packet monitor ordering now considers milliseconds (#2364)#2369
Merged
fix: packet monitor ordering now considers milliseconds (#2364)#2369
Conversation
Added created_at (millisecond precision) as secondary sort key in packet_log queries. Packets within the same second now display in correct arrival order instead of arbitrary DB order. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| LEFT JOIN nodes to_nodes ON pl.to_node = to_nodes."nodeNum" | ||
| WHERE ${whereClause} | ||
| ORDER BY pl.timestamp DESC LIMIT ${limit} OFFSET ${offset} | ||
| ORDER BY pl.timestamp DESC, pl.created_at DESC LIMIT ${limit} OFFSET ${offset} |
There was a problem hiding this comment.
✅ Excellent fix! Adding pl.created_at DESC as a secondary sort key resolves the ordering issue for packets arriving within the same second. Since created_at is stored with millisecond precision (Date.now()), this ensures packets are sorted by actual arrival order even when they have the same timestamp value.
| LEFT JOIN nodes to_nodes ON pl.to_node = to_nodes.nodeNum | ||
| WHERE ${whereClause} | ||
| ORDER BY pl.timestamp DESC LIMIT ${limit} OFFSET ${offset} | ||
| ORDER BY pl.timestamp DESC, pl.created_at DESC LIMIT ${limit} OFFSET ${offset} |
There was a problem hiding this comment.
✅ Perfect consistency! This identical change ensures the same ordering behavior across all database backends (SQLite/MySQL path). The dual maintenance of PostgreSQL and SQLite/MySQL query paths is handled correctly.
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.
Summary
Fixes the second part of #2364 — packet monitor ordering didn't consider milliseconds, so packets within the same second appeared in wrong order.
Root Cause
The
packet_logquery usedORDER BY pl.timestamp DESCbuttimestampis whole seconds (from Meshtastic protobufrxTime). Packets arriving within the same second had undefined relative order.Fix
Added
pl.created_at DESCas a secondary sort key.created_atis already stored asDate.now()(millisecond precision) on every packet insert, but wasn't used in the sort. Applied to both PostgreSQL and SQLite/MySQL query paths.Files Changed
src/db/repositories/misc.tscreated_at DESCtiebreaker to both packet_log ORDER BY clausesTest plan
🤖 Generated with Claude Code