Skip to content

Conversation

ES-Alexander
Copy link
Collaborator

@ES-Alexander ES-Alexander commented Aug 18, 2025

  • Fixed some weird indentation
  • Improved checking sequence for model overrides, which may slightly improve performance when doing a global override

Summary by Sourcery

Refactor modelHelper to tidy up indentation and optimize the model override lookup by checking for a global override before awaiting vehicle and frame readiness.

Enhancements:

  • Fix indentation inconsistencies in vehicle_folder switch statements
  • Reorder checkModelOverrides logic to attempt global override head request before waiting for vehicle_type and frame_type

It's not important to check the connected vehicle type if you're intending to ignore it anyway.
Copy link

sourcery-ai bot commented Aug 18, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refactors modelHelper.ts by cleaning up switch-case indentation in vehicle_folder and optimizing the checkModelOverrides function to attempt a global override before awaiting vehicle metadata, improving code readability and slight performance.

Sequence diagram for the updated checkModelOverrides logic

sequenceDiagram
    participant ModelHelper
    participant Axios
    participant Autopilot
    participant Sleep
    ModelHelper->>Axios: HEAD /userdata/modeloverrides/ALL.glb
    alt Global override exists
        Axios-->>ModelHelper: Success
        ModelHelper-->>ModelHelper: Return master_override
    else Global override missing
        Axios-->>ModelHelper: Error
        ModelHelper->>Autopilot: Check vehicle_type and frame_type
        loop Until vehicle_type and frame_type are available
            ModelHelper->>Sleep: sleep(100)
        end
        ModelHelper->>Axios: HEAD /userdata/modeloverrides/{vehicle_folder}/{frame_name}.glb
        alt Vehicle override exists
            Axios-->>ModelHelper: Success
            ModelHelper-->>ModelHelper: Return vehicle_override
        else Vehicle override missing
            Axios-->>ModelHelper: Error
        end
    end
Loading

Class diagram for updated modelHelper functions

classDiagram
    class modelHelper {
        +vehicle_folder(): string
        +frame_name(vehicle_type: string, frame_type?: number, frame_subtype?: number): string
        +checkModelOverrides(): Promise<string | undefined>
    }
    class autopilot {
        +vehicle_type: string
    }
    modelHelper --> autopilot: uses
Loading

File-Level Changes

Change Details Files
Refactored switch-case indentation for vehicle_folder
  • Aligned return statements under their case blocks
  • Reordered and merged case labels for surface and rover types
  • Standardized default case indentation
core/frontend/src/components/vehiclesetup/viewers/modelHelper.ts
Reordered and optimized model override checks in checkModelOverrides
  • Moved initial type wait loop to after master override check
  • Added early return for successful master override head request
  • Inserted comments clarifying override check sequence
  • Relocated vehicle_override declaration post-wait
core/frontend/src/components/vehiclesetup/viewers/modelHelper.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Consider adding a timeout or max retry count to the polling loop waiting on autopilot.vehicle_type and frame_type to avoid potential infinite blocking.
  • Extract the polling logic into a reusable helper to improve clarity and reduce duplication if used elsewhere.
  • Add an explicit default return or error throw at the end of checkModelOverrides to handle the case where neither master nor vehicle-specific override is found.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider adding a timeout or max retry count to the polling loop waiting on autopilot.vehicle_type and frame_type to avoid potential infinite blocking.
- Extract the polling logic into a reusable helper to improve clarity and reduce duplication if used elsewhere.
- Add an explicit default return or error throw at the end of checkModelOverrides to handle the case where neither master nor vehicle-specific override is found.

## Individual Comments

### Comment 1
<location> `core/frontend/src/components/vehiclesetup/viewers/modelHelper.ts:27` </location>
<code_context>
+    case MavType.MAV_TYPE_GROUND_ROVER:
+      return 'rover'
     default:
-    return autopilot.vehicle_type?.toLowerCase() || 'unknown'
+      return autopilot.vehicle_type?.toLowerCase() || 'unknown'
   }
</code_context>

<issue_to_address>
Returning 'unknown' may mask unexpected vehicle types.

Consider adding a warning or error log when 'unknown' is returned to help identify unsupported or misconfigured vehicle types.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    default:
      return autopilot.vehicle_type?.toLowerCase() || 'unknown'
=======
    default:
      console.warn(
        `Unknown or unsupported vehicle type encountered: mav_type=${mav_type}, autopilot.vehicle_type=${autopilot.vehicle_type}`
      );
      return autopilot.vehicle_type?.toLowerCase() || 'unknown'
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Williangalvani Williangalvani merged commit 3067308 into bluerobotics:master Aug 18, 2025
6 checks passed
@ES-Alexander ES-Alexander deleted the model-override-fixups branch September 29, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants