feat: precompute airtime_ms at packet storage time#64
Open
dmduran12 wants to merge 1 commit intorightup:devfrom
Open
feat: precompute airtime_ms at packet storage time#64dmduran12 wants to merge 1 commit intorightup:devfrom
dmduran12 wants to merge 1 commit intorightup:devfrom
Conversation
Calculate and store airtime_ms when packets are received, eliminating the need for frontend to recalculate airtime for every packet on every chart render. Changes: - Add airtime_ms REAL column to packets table (migration 4) - Store airtime_ms in packet record at receive time using AirtimeManager - Include airtime_ms in all packet query responses This reduces chart render time from O(n * calculation) to O(n) for airtime aggregation, particularly beneficial on resource-constrained devices like Raspberry Pi with large packet histories. Old packets without airtime_ms return NULL; frontend can fall back to client-side calculation until data ages out via normal cleanup. Co-Authored-By: Warp <agent@warp.dev>
Author
|
we can also implement a one-time database backfill that adds this to all packets... but... it was starting to feel complex. If you'd like, I can submit it, but I think the front can take the brunt of that work with fallback methods to calculate airtime based on current radio settings IF the API doesn't return airtime. |
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
Pre-calculate and store
airtime_mswhen packets are received, eliminating repeated client-side airtime calculations on every chart render.Problem
Currently, the frontend calculates airtime for every packet each time a chart is rendered:
For large packet histories (e.g., 75K packets), this results in:
Solution
Calculate airtime once at receive time and store it with the packet:
Changes
Database (
sqlite_handler.py)airtime_ms REALcolumn topacketstablestore_packet()INSERT to includeairtime_msget_recent_packets(),get_filtered_packets(),get_packet_by_hash()to returnairtime_msPacket Processing (
engine.py)airtime_msusing existingAirtimeManager.calculate_airtime()when building packet recordAPI Response
Packet responses now include the pre-calculated value:
{ "timestamp": 1705728000, "type": 4, "raw_packet": "...", "airtime_ms": 226.3 }Migration Path
airtime_mscalculated and stored automaticallyairtime_ms = NULL; frontend falls back to client-side calculationPerformance Impact
Co-Authored-By: Warp agent@warp.dev