Skip to content

fix: refresh deferred imported view on first display#459

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master
Jul 17, 2026
Merged

fix: refresh deferred imported view on first display#459
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71

@wyu71 wyu71 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Refresh the imported timeline when its deferred view is first created. 在延迟创建的已导入视图首次显示时刷新时间线。

Log: 修复已导入界面首次点击不显示的问题
Influence: 已导入视图首次进入和非默认视图懒加载

Summary by Sourcery

Ensure deferred thumbnail views activate and refresh correctly when first displayed, so imported timelines render on initial entry.

Bug Fixes:

  • Fix imported view not rendering its timeline on the first click when created via deferred loading.

Enhancements:

  • Adjust deferred view activation to respond to current view type changes and initial completion, improving lazy-loaded non-default views behavior.

Refresh the imported timeline when its deferred view is first created.
在延迟创建的已导入视图首次显示时刷新时间线。

Log: 修复已导入界面首次点击不显示的问题
Influence: 已导入视图首次进入和非默认视图懒加载
@sourcery-ai

sourcery-ai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR fixes a bug where the imported (non-default) timeline view fails to render on first display when created lazily via DeferredView, by explicitly triggering the loader activation and a one-time timeline refresh when the view first becomes visible.

Sequence diagram for lazy imported view first display fix

sequenceDiagram
    actor User
    participant GStatus
    participant DeferredView
    participant Loader
    participant HaveImportedView
    participant timeline

    User->>GStatus: change currentViewType
    GStatus-->>DeferredView: currentViewTypeChanged
    DeferredView->>DeferredView: loadCurrentView()
    alt currentViewType === viewType and !active
        DeferredView->>Loader: set active = true
        Loader-->>HaveImportedView: create Component
        HaveImportedView->>HaveImportedView: Component.onCompleted
        HaveImportedView->>Qt: Qt.callLater(function)
        Qt-->>HaveImportedView: invoke deferred function
        alt visible and !initialContentInitialized
            HaveImportedView->>HaveImportedView: flushView()
            HaveImportedView->>timeline: refresh()
            HaveImportedView->>HaveImportedView: initialContentInitialized = true
        end
    end
Loading

File-Level Changes

Change Details Files
Ensure deferred views only activate when their view type becomes current, and react to view-type changes instead of implicit first-load behavior.
  • Removed the loaded-once flag and its binding-based activation logic for the Loader
  • Set the Loader to start inactive and added a loadCurrentView() helper that activates it only when the global current view type matches the Loader's viewType
  • Connected to GStatus.currentViewTypeChanged to call loadCurrentView() whenever the current view changes
  • Invoked loadCurrentView() in Component.onCompleted so the Loader activates immediately if the current view is already this view type at construction
src/qml/ThumbnailImageView/DeferredView.qml
Guarantee that the imported timeline view refreshes its content at least once after first construction when it is already visible, covering the lazy/deferred creation case.
  • Introduced an initialContentInitialized flag to track whether the view has had a visible refresh
  • Set initialContentInitialized to true after flushView performs a timeline refresh and related UI updates
  • On component completion, scheduled a Qt.callLater callback that checks if the view is visible and not yet initialized, and calls flushView() to populate the timeline
  • Kept the existing connection of sigFlushHaveImportedView to flushView, while ensuring the first-render path works even when onVisibleChanged is not triggered
src/qml/ThumbnailImageView/HaveImportedView/HaveImportedView.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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码通过懒加载机制优化了视图加载性能,并妥善修复了首次渲染空白的问题
逻辑正确,性能提升明显,且不存在安全漏洞,故给予满分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

DeferredView.qml 中移除了 loadedOnce 逻辑,改为通过 Connections 监听 GStatus.currentViewType 变化来按需激活 Loader,逻辑闭环完整。HaveImportedView.qml 中在 Component.onCompleted 使用 Qt.callLater 延迟调用 flushView(),有效避免了组件首次加载时因 visible 状态未变化而导致的时间轴未刷新问题。
潜在问题:无
建议:无需修改

  • 2.代码质量(优秀)✓

代码结构清晰,命名规范。新增的注释准确地解释了 initialContentInitialized 属性的作用以及 Qt.callLater 使用的背景原因,有助于后续维护者理解懒加载与可视性刷新的交互逻辑。
潜在问题:无
建议:无需修改

  • 3.代码性能(高效)✓

原先的 loadedOnce 机制会导致 Loader 一旦加载便保持常驻活跃,造成不必要的资源占用。修改后的 active: false 结合按需激活策略,实现了真正的懒加载,显著降低了内存和 CPU 开销。
潜在问题:无
建议:无需修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码修改仅涉及 QML 视图加载逻辑和状态管理,未引入任何外部输入处理、文件操作或系统命令调用,不存在安全攻击面。

  • 建议:无需修复

■ 【改进建议代码示例】

// 代码已经非常完善,无需额外修复,保持原样即可。
// DeferredView.qml
Loader {
    property int viewType: -1

    anchors.fill: parent
    asynchronous: false
    active: false

    function loadCurrentView() {
        if (!active && GStatus.currentViewType === viewType)
            active = true
    }

    Connections {
        target: GStatus
        function onCurrentViewTypeChanged() {
            loadCurrentView()
        }
    }

    Component.onCompleted: loadCurrentView()
}

// HaveImportedView.qml
property bool initialContentInitialized: false

function flushView() {
    // ...
    initialContentInitialized = true
}

Component.onCompleted: {
    GStatus.sigFlushHaveImportedView.connect(flushView)

    Qt.callLater(function() {
        if (visible && !initialContentInitialized)
            flushView()
    })
}

@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 left some high level feedback:

  • In DeferredView.qml, consider deriving active directly from GStatus.currentViewType === viewType (e.g. via a binding or when-style condition) instead of imperatively setting it in loadCurrentView, to avoid potential state drift if currentViewType changes in unexpected sequences.
  • In HaveImportedView.qml, the initialContentInitialized flag is only set in flushView; if the view is hidden and reshown without a flush, you may want to reset this flag appropriately so the Qt.callLater fallback behaves consistently across multiple show/hide cycles.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In DeferredView.qml, consider deriving `active` directly from `GStatus.currentViewType === viewType` (e.g. via a binding or `when`-style condition) instead of imperatively setting it in `loadCurrentView`, to avoid potential state drift if `currentViewType` changes in unexpected sequences.
- In HaveImportedView.qml, the `initialContentInitialized` flag is only set in `flushView`; if the view is hidden and reshown without a flush, you may want to reset this flag appropriately so the Qt.callLater fallback behaves consistently across multiple show/hide cycles.

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.

@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 6462abb into linuxdeepin:master Jul 17, 2026
18 of 20 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