feat: precompute airtime_ms at packet storage time #64
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