Skip to content

refactor(Region): optimize SelectCity search - #1130

Merged
ArgoZhang merged 3 commits into
masterfrom
dev-city
Sep 1, 2026
Merged

refactor(Region): optimize SelectCity search#1130
ArgoZhang merged 3 commits into
masterfrom
dev-city

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Sep 1, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #1129

Summary By Copilot

  • debounce SelectCity search input to reduce JavaScript/.NET interop calls during continuous typing
  • lazily build per-instance province and city pinyin indexes and reuse them for filtering and highlighting
  • cache filtered provinces until the search text changes and skip duplicate searches
  • add stable render keys for province and city elements
  • cover Chinese, pinyin, and cleared searches with component tests

Regression?

  • Yes
  • No

The public component API, result presentation, and selection behavior remain unchanged.

Risk

  • High
  • Medium
  • Low

The change is isolated to SelectCity search dispatch, filtering, and rendering. Search indexes remain scoped to each component instance so custom service data is not shared across instances.

Verification

  • Manual (required)

  • Automated

  • passed all 4 UnitTestRegion tests on net10.0

  • checked SelectCity.razor.js with Node.js syntax validation

  • checked the branch diff for whitespace errors

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Improve SelectCity search performance while preserving its public API, presentation, and selection behavior.

Enhancements:

  • Optimize SelectCity search by reducing interop calls, reusing per-instance search indexes, caching filtered results, and avoiding duplicate searches.
  • Add stable rendering keys for province and city entries.

Tests:

  • Add component coverage for Chinese, pinyin, and cleared SelectCity searches.

@bb-auto bb-auto Bot added the enhancement New feature or request label Sep 1, 2026
@bb-auto bb-auto Bot added this to the v10.0.0 milestone Sep 1, 2026
@sourcery-ai

sourcery-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Reviewer's Guide

SelectCity search now reduces interop and filtering overhead through debouncing, duplicate suppression, and per-instance cached pinyin/filter indexes, while stable render keys preserve UI state and bUnit tests cover Chinese, pinyin, and cleared searches without changing the public API or selection behavior.

Sequence diagram for debounced SelectCity search

sequenceDiagram
    participant User
    participant SearchInput
    participant SelectCityJS
    participant SelectCity

    User->>SearchInput: type search text
    SearchInput->>SelectCityJS: Input.composition
    SelectCityJS->>SelectCityJS: debounce
    alt input is connected and value is unchanged
        SelectCityJS->>SelectCity: invokeMethodAsync(triggerSearch, value)
        SelectCity->>SelectCity: TriggerSearch(value)
        alt search text changed
            SelectCity->>SelectCity: FilterProvinces(searchText)
            SelectCity->>SelectCity: StateHasChanged()
        else duplicate search
            SelectCity-->>SelectCity: return
        end
    end
Loading

Flow diagram for SelectCity search filtering

flowchart TD
    A[Search text received] --> B{Text changed?}
    B -- No --> C[Skip duplicate search]
    B -- Yes --> D[Cache filtered provinces]
    D --> E{Contains Chinese?}
    E -- Yes --> F[Match province and city names]
    E -- No --> G[Build or reuse pinyin indexes]
    G --> H[Match province and city pinyin]
    F --> I[Render filtered provinces]
    H --> I
    I --> J[Reuse pinyin index for city highlighting]
Loading

File-Level Changes

Change Details Files
Debounced browser-to-.NET search dispatch and eliminated redundant searches during typing.
  • Wrapped composition input handling in a debounce callback.
  • Skipped invocation when the input is detached or its value has changed since scheduling.
  • Ignored duplicate normalized search text in the component.
src/components/BootstrapBlazor.Region/Components/SelectCity.razor.js
src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs
Added per-component cached indexes and cached filtered province results for Chinese and pinyin searches.
  • Lazily generated province and city pinyin indexes scoped to each SelectCity instance.
  • Stored filtered provinces when search text changes and reset them when search is disabled or cleared.
  • Reused the city pinyin index for highlighting matching cities.
src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs
Improved render stability for dynamically filtered province and city elements.
  • Added stable Blazor keys to province containers and city list items.
  • Rendered from the cached filtered province collection.
src/components/BootstrapBlazor.Region/Components/SelectCity.razor
Added component-level coverage for Chinese, pinyin, and cleared searches.
  • Initialized bUnit services and JS interop for SelectCity tests.
  • Verified province filtering, pinyin city highlighting, and restoration of all provinces after clearing search.
test/UnitTestRegion/RegionTest.cs
test/UnitTestRegion/UnitTestRegion.csproj

Assessment against linked issues

Issue Objective Addressed Explanation
#1129 Debounce SelectCity search input and avoid duplicate searches and unnecessary JavaScript/.NET interop calls during continuous or unchanged input.
#1129 Lazily build and reuse per-component province and city pinyin indexes, cache filtered provinces until the search text changes, and reuse cached pinyin for filtering and match highlighting.
#1129 Preserve existing presentation and selection behavior while adding stable render keys and automated coverage for Chinese, pinyin, and cleared searches.

Possibly linked issues


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

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto approved by bb-auto

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


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.

@ArgoZhang
ArgoZhang merged commit de51b88 into master Sep 1, 2026
3 checks passed
@ArgoZhang
ArgoZhang deleted the dev-city branch September 1, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(Region): optimize SelectCity search

1 participant