Skip to content

perf(qml): lazy-load AlbumTitle collectionCombo for wide-screen startup#446

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master
Jun 30, 2026
Merged

perf(qml): lazy-load AlbumTitle collectionCombo for wide-screen startup#446
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71

@wyu71 wyu71 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Wrap the narrow-screen Y/M/D/All ComboBox in a Loader with a once-latch on collectionComboEverNarrow so wide-screen startup no longer eagerly instantiates a DTK ComboBox (popup/menu/listview). active avoids binding window.width to prevent hover-time rebuild jitter that lost highlight.

将窄屏年月日下拉框 ComboBox 包入 Loader,配合 collectionComboEverNarrow 单调锁,宽屏启动不再 eager 实例化 DTK ComboBox。active 不绑 window.width, 避免 hover 时重建抖动导致下拉菜单高亮丢失。

Log: 延迟加载标题栏年月日下拉框,优化宽屏启动
Influence: 宽屏启动减少一个 DTK ComboBox 实例化开销;窄屏功能与 hover 高亮行为不变。

Summary by Sourcery

Lazy-load the narrow-screen Y/M/D/All ComboBox in the album title bar to avoid instantiating it on wide-screen startup while keeping narrow-screen behavior consistent.

Enhancements:

  • Introduce a Loader with a monotonic latch to create the collection ComboBox only after the window has been narrow at least once, reducing startup overhead on wide screens.
  • Adjust layout width and button enablement logic to depend on collection view state instead of the ComboBox instance, preserving interactions when the ComboBox is not loaded.
  • Ensure bidirectional sync between the button group and the ComboBox current index via an explicit update on collection view index changes.

@sourcery-ai

sourcery-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

Lazy-load the Y/M/D/All ComboBox in AlbumTitle.qml via a Loader that only instantiates after a narrow-width condition has ever been met, and update all interactions to go through the Loader item while keeping collection view selection and button group behavior in sync.

Sequence diagram for lazy-loaded Y_M_D_All ComboBox via Loader in AlbumTitle

sequenceDiagram
    participant Window
    participant AlbumTitle
    participant collectionComboLoader
    participant collectionCombo
    participant GStatus
    participant collectionBtnBox

    Window->>AlbumTitle: onWidthChanged
    alt [window.width <= showCollComboWidth]
        AlbumTitle->>AlbumTitle: collectionComboEverNarrow = true
    end

    AlbumTitle->>collectionComboLoader: active = collectionComboEverNarrow && GStatus.currentViewType === Album.Types.ViewCollecttion && albumControl.getYears().length !== 0
    alt [active becomes true]
        collectionComboLoader->>collectionCombo: create ComboBox from sourceComponent
        collectionCombo->>GStatus: Component.onCompleted connect currentCollecttionViewIndexChanged to updateIndex
        GStatus-->>collectionCombo: currentCollecttionViewIndexChanged
        collectionCombo->>collectionCombo: updateIndex()
        collectionCombo->>collectionBtnBox: setChecked(collectionCombo.currentIndex)
    end

    GStatus-->>AlbumTitle: currentCollecttionViewIndex changed
    AlbumTitle->>collectionCombo: updateIndex()
    collectionCombo->>collectionBtnBox: setChecked(collectionCombo.currentIndex)

    collectionBtnBox->>collectionCombo: setCurrentIndex(index)
    collectionCombo->>collectionCombo: onCurrentIndexChanged
    alt [!blocksignal]
        collectionCombo->>AlbumTitle: collectionBtnClicked(currentIndex)
    end
    collectionCombo->>collectionBtnBox: setChecked(currentIndex)

    note over Window,collectionComboLoader: Wide-screen startup (window.width > showCollComboWidth) keeps collectionComboLoader inactive, avoiding eager ComboBox instantiation
Loading

File-Level Changes

Change Details Files
Wrap the collection ComboBox in a Loader and gate its instantiation on a once-latch for narrow-width windows to avoid eager DTK ComboBox creation on wide-screen startup.
  • Introduce collectionComboEverNarrow property and set it when window width is ever <= showCollComboWidth, including a startup re-check in Component.onCompleted.
  • Replace direct references to collectionCombo with collectionComboLoader.item where the ComboBox might not yet exist (visibility toggling, button click handlers, width calculations).
  • Create Loader collectionComboLoader with active conditions based on collectionComboEverNarrow, current view type, and year model presence, and keep visible bound only to current view type, years, and window width.
  • Move the ComboBox into sourceComponent of the Loader, preserving layout constraints and the visible expression based on refreshVisible, current view type, years, and window width.
src/qml/AlbumTitle.qml
Ensure button group, status bar, and global state stay correctly synchronized with the lazily-loaded ComboBox selection.
  • Change range1Button enabled condition to use GStatus.currentCollecttionViewIndex instead of collectionCombo.currentIndex so it no longer depends on ComboBox existence.
  • Extend ComboBox updateIndex to also update collectionBtnBox checked state based on GStatus.currentCollecttionViewIndex.
  • Call updateIndex() from ComboBox Component.onCompleted after connecting to GStatus.currentCollecttionViewIndexChanged to initialize selection and button state.
  • Keep onCurrentIndexChanged logic to drive collectionBtnClicked and collectionBtnBox.setChecked, guarded by blocksignal, within the Loader-hosted ComboBox.
src/qml/AlbumTitle.qml

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

@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 found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/qml/AlbumTitle.qml" line_range="350-356" />
<code_context>
+                        collectionCombo.currentIndex = index
+                    }

-                function updateIndex() {
-                    blocksignal = true
-                    collectionCombo.currentIndex = GStatus.currentCollecttionViewIndex
-                    blocksignal = false
-                }
+                    function updateIndex() {
+                        blocksignal = true
+                        collectionCombo.currentIndex = GStatus.currentCollecttionViewIndex
+                        blocksignal = false
+                        collectionBtnBox.setChecked(collectionCombo.currentIndex)
+                    }

-                onCurrentIndexChanged: {
-                    if (!blocksignal)
-                        collectionBtnClicked(currentIndex)
</code_context>
<issue_to_address>
**suggestion (performance):** Avoid redundant setChecked calls in updateIndex/onCurrentIndexChanged.

Because `updateIndex` sets `collectionCombo.currentIndex`, `onCurrentIndexChanged` will still run and call `collectionBtnBox.setChecked(currentIndex)` again, causing the same work twice for each external index sync. Consider either dropping the `setChecked` call from `updateIndex` or guarding the `onCurrentIndexChanged` path with `blocksignal` so only one code path updates `collectionBtnBox`.
</issue_to_address>

### Comment 2
<location path="src/qml/AlbumTitle.qml" line_range="335-331" />
<code_context>
+            Loader {
</code_context>
<issue_to_address>
**suggestion:** Simplify visibility handling between Loader and inner ComboBox.

The Loader already controls visibility using these conditions, while the inner ComboBox re-evaluates them independently. Consider removing the ComboBox’s visibility expression (or binding it directly to `Loader.visible`) to avoid duplicated logic and the risk of the two sets of conditions drifting out of sync.

Suggested implementation:

```
            Loader {
                id: collectionComboLoader
                Layout.minimumWidth: 100
                Layout.maximumWidth: 120
                Layout.fillWidth: true

                // Ensure any inner ComboBox uses the Loader's visibility instead of duplicating conditions
                onLoaded: {
                    if (item && item.visible !== undefined) {
                        item.visible = Qt.binding(function() { return collectionComboLoader.visible })
                    }
                }

```

1. If the ComboBox inside this `Loader` currently has its own `visible: ...` expression (for example: `visible: window.width <= showCollComboWidth && collectionComboEverNarrow`), remove that expression so it becomes either:
   - `visible: true` (letting the `onLoaded` binding above drive visibility), or
   - omit `visible` entirely if it is not needed elsewhere.
2. If the ComboBox is defined via `sourceComponent` instead of `source`, and you prefer a purely declarative approach, you can instead:
   - Add `visible: collectionComboLoader.visible` directly inside that `ComboBox { ... }` block,
   - And then remove the `onLoaded` handler from the `Loader`.
3. Make sure the existing visibility / active logic remains only on the `Loader` (e.g. `active:` or `visible:` on `collectionComboLoader`) so there is a single source of truth for when the dropdown should appear.
</issue_to_address>

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.

Comment thread src/qml/AlbumTitle.qml
Comment thread src/qml/AlbumTitle.qml
Wrap the narrow-screen Y/M/D/All ComboBox in a Loader with a once-latch
on collectionComboEverNarrow so wide-screen startup no longer eagerly
instantiates a DTK ComboBox (popup/menu/listview). active avoids binding
window.width to prevent hover-time rebuild jitter that lost highlight.

将窄屏年月日下拉框 ComboBox 包入 Loader,配合 collectionComboEverNarrow
单调锁,宽屏启动不再 eager 实例化 DTK ComboBox。active 不绑 window.width,
避免 hover 时重建抖动导致下拉菜单高亮丢失。

Log: 延迟加载标题栏年月日下拉框,优化宽屏启动
Influence: 宽屏启动减少一个 DTK ComboBox 实例化开销;窄屏功能与 hover 高亮行为不变。
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx, wyu71

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wyu71 wyu71 merged commit 962229c into linuxdeepin:master Jun 30, 2026
18 of 19 checks passed
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.

3 participants