Skip to content

fix(view): defer visible date range refresh#463

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

fix(view): defer visible date range refresh#463
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71

@wyu71 wyu71 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Coalesce viewport changes and avoid clearing dates before layout is ready. 合并视口变化,并避免在布局完成前错误清空日期。

Log: 修复合集可见日期范围刷新异常
Influence: 合集滚动和缩略图尺寸变化时的标题日期显示

Summary by Sourcery

Defer and coalesce visible date range updates in the album thumbnail list view to avoid incorrect clearing during scrolling or layout changes.

Bug Fixes:

  • Prevent the album title date range from being cleared when thumbnails are present during scroll and layout updates.

Enhancements:

  • Introduce a short debounce timer to coalesce scroll and layout changes before recomputing the visible thumbnail date range.

Coalesce viewport changes and avoid clearing dates before layout is ready.
合并视口变化,并避免在布局完成前错误清空日期。

Log: 修复合集可见日期范围刷新异常
Influence: 合集滚动和缩略图尺寸变化时的标题日期显示
@sourcery-ai

sourcery-ai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR defers and coalesces updates to the visible date range calculation in the album thumbnail list view, ensuring date labels update only after scroll/layout changes settle and correctly handle the empty model case.

Sequence diagram for deferred visible date range refresh

sequenceDiagram
    actor User
    participant ThumbnailListViewAlbum as ThumbnailListViewAlbum
    participant vbar as ScrollBar
    participant timeScopeTimer as Timer

    User->>vbar: scroll
    vbar->>ThumbnailListViewAlbum: onPositionChanged
    ThumbnailListViewAlbum->>ThumbnailListViewAlbum: scheduleTimeScope()
    ThumbnailListViewAlbum->>timeScopeTimer: restart()

    timeScopeTimer-->>ThumbnailListViewAlbum: onTriggered
    ThumbnailListViewAlbum->>ThumbnailListViewAlbum: totalTimeScope()
    alt thumbnailModel.rowCount() > 0 and visilbeIndexs.length > 0
        ThumbnailListViewAlbum->>ThumbnailListViewAlbum: timeChanged(str)
    else thumbnailModel.rowCount() === 0
        ThumbnailListViewAlbum->>ThumbnailListViewAlbum: timeChanged("")
    end
Loading

File-Level Changes

Change Details Files
Coalesce viewport changes and defer visible date range calculation using a timer instead of immediate calls.
  • Added scheduleTimeScope() helper to restart a coalescing timer before recalculating the visible time scope.
  • Introduced a one-shot Timer (timeScopeTimer) with a short interval that triggers totalTimeScope() after scroll/layout events.
  • Updated scroll bar position and cell width change handlers to call scheduleTimeScope() rather than totalTimeScope() directly.
src/qml/Control/ListView/ThumbnailListViewAlbum.qml
Fix visible date range clearing logic when the thumbnail model is empty.
  • Adjusted totalTimeScope() else branch to clear the time label only when the thumbnail model rowCount() is zero, avoiding incorrect clears while data is present.
src/qml/Control/ListView/ThumbnailListViewAlbum.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.语法逻辑(完全正确)✓

scheduleTimeScope() 函数与 timeScopeTimer 定时器的结合使用符合 QML 语法规范。totalTimeScope() 中的 else if (thumbnailModel.rowCount() === 0) 判断逻辑准确,确保仅在模型为空时才清空时间显示,修复了视口无可见项时的逻辑缺陷。
潜在问题:无
建议:无

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

新增的代码块包含了清晰的注释,函数命名 scheduleTimeScope 准确表达了防抖调度的意图。代码结构清晰,易于维护,符合 QML 编码规范。
潜在问题:无
建议:无

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

原本在 vbar.onPositionChangedonRealCellWidthChanged 事件中频繁直接调用 totalTimeScope(),会导致严重的性能开销。修改后使用 16ms 间隔的 Timer 进行事件合并(防抖),大幅减少了不必要的计算和系统调用,显著提升了滑动和缩放时的流畅度。
潜在问题:无
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码变更仅为前端 QML 逻辑优化,不涉及外部输入解析、命令执行或敏感数据操作,不存在安全风险。

  • 建议:无

■ 【改进建议代码示例】

// 当前代码已非常完善,无需进一步修改。

@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 1 issue, and left some high level feedback:

  • The change from else to else if (thumbnailModel.rowCount() === 0) alters behavior when there are no visible indexes but the model is non-empty; please confirm this case is either impossible or explicitly handled elsewhere to avoid leaving a stale time label.
  • Consider avoiding the hard-coded 16 ms timer interval (e.g., by deriving it from the display refresh rate or at least centralizing it as a named constant) to make the throttling intent clearer and easier to adjust later.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The change from `else` to `else if (thumbnailModel.rowCount() === 0)` alters behavior when there are no visible indexes but the model is non-empty; please confirm this case is either impossible or explicitly handled elsewhere to avoid leaving a stale time label.
- Consider avoiding the hard-coded `16` ms timer interval (e.g., by deriving it from the display refresh rate or at least centralizing it as a named constant) to make the throttling intent clearer and easier to adjust later.

## Individual Comments

### Comment 1
<location path="src/qml/Control/ListView/ThumbnailListViewAlbum.qml" line_range="108-118" />
<code_context>
+
+    Timer {
+        id: timeScopeTimer
+        interval: 16
+        repeat: false
+        onTriggered: totalTimeScope()
</code_context>
<issue_to_address>
**suggestion:** Consider avoiding the hard-coded 16ms timer interval or documenting the rationale.

This value assumes a ~60 FPS refresh rate and may not behave as intended on different displays. If you just need to batch layout/scroll changes to the next event loop turn, consider `Qt.callLater` or a 0ms single-shot `Timer` instead. If you keep the 16ms delay, define a named constant (e.g. `FRAME_INTERVAL_MS`) to make the intent explicit and avoid a magic number.

```suggestion
    // Coalesce scroll and layout changes before querying the visible date range.
    // Use a frame-based delay (~60 FPS) to batch updates with UI redraws.
    readonly property int FRAME_INTERVAL_MS: 16

    function scheduleTimeScope() {
        timeScopeTimer.restart()
    }

    Timer {
        id: timeScopeTimer
        interval: FRAME_INTERVAL_MS
        repeat: false
        onTriggered: totalTimeScope()
    }
```
</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 on lines +108 to +118
// Coalesce scroll and layout changes before querying the visible date range.
function scheduleTimeScope() {
timeScopeTimer.restart()
}

Timer {
id: timeScopeTimer
interval: 16
repeat: false
onTriggered: totalTimeScope()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Consider avoiding the hard-coded 16ms timer interval or documenting the rationale.

This value assumes a ~60 FPS refresh rate and may not behave as intended on different displays. If you just need to batch layout/scroll changes to the next event loop turn, consider Qt.callLater or a 0ms single-shot Timer instead. If you keep the 16ms delay, define a named constant (e.g. FRAME_INTERVAL_MS) to make the intent explicit and avoid a magic number.

Suggested change
// Coalesce scroll and layout changes before querying the visible date range.
function scheduleTimeScope() {
timeScopeTimer.restart()
}
Timer {
id: timeScopeTimer
interval: 16
repeat: false
onTriggered: totalTimeScope()
}
// Coalesce scroll and layout changes before querying the visible date range.
// Use a frame-based delay (~60 FPS) to batch updates with UI redraws.
readonly property int FRAME_INTERVAL_MS: 16
function scheduleTimeScope() {
timeScopeTimer.restart()
}
Timer {
id: timeScopeTimer
interval: FRAME_INTERVAL_MS
repeat: false
onTriggered: totalTimeScope()
}

@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 880a9c3 into linuxdeepin:master Jul 20, 2026
17 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