-
Notifications
You must be signed in to change notification settings - Fork 35
Fix TrackedMobileRadio asserted_location_changed_at #1017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the initialization and backfill of asserted_location_changed_at for tracked mobiles and adds a one-shot command to migrate missing values.
- Change
add_db_recordto acceptOption<i64>for location and populatenum_location_asserts. - Update
TrackedMobileRadio::newto setasserted_location_changed_atwhen a location is present. - Implement
post_migrate_mobile_tracker_locationsand wirePostMigrateMobileTrackerinto the CLI. - Add new tests covering location updates for radios.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| mobile_config/tests/mobile_radio_tracker.rs | Update test function names, adapt signature to Option<i64>, add tests for location changes |
| mobile_config/tests/gateway_service.rs | Update gateway tests to pass Some(asset_hex_idx) to add_db_record |
| mobile_config/tests/common/mod.rs | Change add_db_record and add_mobile_hotspot_infos to use Option<i64> and include num_location_asserts |
| mobile_config/src/mobile_radio_tracker.rs | Set initial asserted_location_changed_at, remove old CSV logic, add post_migrate_mobile_tracker_locations |
| mobile_config/src/main.rs | Replace MigrateMobileTracker with PostMigrateMobileTracker command in CLI |
Comments suppressed due to low confidence (3)
mobile_config/src/mobile_radio_tracker.rs:301
- Add a doc comment (
///) above this function to describe its purpose, parameters, and high-level behavior, which will help future maintainers understand the migration steps.
pub async fn post_migrate_mobile_tracker_locations(
mobile_config/src/main.rs:48
- Introduce an integration or end-to-end test for the
PostMigrateMobileTrackercommand to verify that it correctly backfillsasserted_location_changed_atunder various scenarios.
Cmd::PostMigrateMobileTracker => {
mobile_config/tests/mobile_radio_tracker.rs:10
- [nitpick] The test name
mt_handle_entity_duplicatesis abbreviated; consider renaming it tomobile_tracker_handle_entity_duplicatesfor clarity and consistency with other descriptive test names.
async fn mt_handle_entity_duplicates(pool: PgPool) {
| ); | ||
|
|
||
| for (k, _v) in tracked_radios { | ||
| if let Some(mobile_info) = mobile_infos.iter().find(|v| v.entity_key == k) { |
Copilot
AI
Jul 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid O(n²) lookups, build a HashMap from mobile_infos keyed by entity_key before this loop so you can do O(1) lookups instead of .iter().find() on each iteration.
| if let Some(mobile_info) = mobile_infos.iter().find(|v| v.entity_key == k) { | |
| if let Some(mobile_info) = mobile_infos_map.get(&k) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small number of elements (<200) is expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is swap around the iteration.
for mobile_radio in mobile_radios {
if tracked_radios.contains_key(&mobile_radio.entity_key) {
// ... Do the work
}
}
asserted_location_changed_at=refreshed_atif a new (arrived) radio has location.Add PostMigrateMobileTracker command to fill in missing values caused by a bug
Ex:
RUST_LOG=debug .mobile-config -c ./mobile-config.toml post-migrate-mobile-tracker