Skip to content

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Oct 24, 2025

Changed the expired notification cleanup mechanism from fetching and
processing expired entities to directly deleting them from storage.
The previous implementation used fetchExpiredEntities to get expired
notifications and then closed them individually, which was inefficient
for large datasets. The new approach adds removeEntitiesByExpiredTime
method that directly deletes expired records from database and memory
storage, improving performance by eliminating unnecessary data retrieval
and processing.

Added trigger to automatically clean expired notifications when
notification center becomes visible, ensuring users always see current
notifications without expired ones cluttering the interface. This on-
demand cleanup approach is more efficient than the previous timer-based
periodic cleanup.

Log: Optimized notification cleanup to remove expired notifications when
opening notification center

Influence:

  1. Test opening notification center to verify expired notifications are
    automatically removed
  2. Verify notification count displays correctly after cleanup
  3. Test notification persistence for non-expired notifications
  4. Check database storage efficiency after implementing direct deletion
  5. Verify memory usage improvement with the optimized cleanup approach
  6. Test notification center performance with large number of
    notifications

refactor: 优化过期通知清理实现

将过期通知清理机制从获取和处理过期实体改为直接从存储中删除。之前的实现使
用 fetchExpiredEntities 获取过期通知然后逐个关闭,对于大数据集效率低下。
新方法添加了 removeEntitiesByExpiredTime 方法,直接从数据库和内存存储中
删除过期记录,通过消除不必要的数据检索和处理来提高性能。

添加了在通知中心变为可见时自动清理过期通知的触发器,确保用户始终看到当前
通知而不会被过期通知干扰界面。这种按需清理方法比之前的基于定时器的定期清
理更高效。

Log: 优化通知清理功能,在打开通知中心时自动移除过期通知

Influence:

  1. 测试打开通知中心验证过期通知是否自动移除
  2. 验证清理后通知计数显示是否正确
  3. 测试非过期通知的持久化存储
  4. 检查实现直接删除后的数据库存储效率
  5. 验证优化清理方法后的内存使用改进
  6. 测试通知中心在大量通知情况下的性能表现

Summary by Sourcery

Refactor the expired notification cleanup to directly delete outdated records and invoke cleanup on demand when opening the notification center, improving performance and eliminating unnecessary data fetching.

Enhancements:

  • Replace fetch-and-close mechanism with direct deletion of expired notifications via removeEntitiesByExpiredTime in both DB and memory accessors
  • Remove the periodic timer-based cleanup and onCleanupExpiredNotifications logic from NotificationManager
  • Trigger on-demand removal of expired notifications when the notification center becomes visible via D-Bus
  • Update DataAccessor interface and proxy to replace fetchExpiredEntities with removeEntitiesByExpiredTime

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 emitting notificationClosed signals or an explicit update notification after direct deletes so clients can react to timeouts just like before.
  • Double-check that QList::removeIf is available on your target Qt/C++ version or switch to a portable loop-and-erase implementation.
  • You may still end up with stale records if the center is never opened—consider running cleanup on startup or at another strategic point.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider emitting notificationClosed signals or an explicit update notification after direct deletes so clients can react to timeouts just like before.
- Double-check that QList::removeIf is available on your target Qt/C++ version or switch to a portable loop-and-erase implementation.
- You may still end up with stale records if the center is never opened—consider running cleanup on startup or at another strategic point.

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.

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 24, 2025

Reviewer's Guide

This refactor replaces the previous fetch-and-close expired notifications workflow with a direct deletion API in both database and memory layers, removes the periodic cleanup timer in favor of an on-demand trigger when the notification center is shown, and wires up a new D-Bus slot to invoke this more efficient cleanup.

Sequence diagram for on-demand expired notification cleanup when notification center is shown

sequenceDiagram
    actor User
    participant NotificationCenterPanel
    participant DAppletBridge
    participant NotifyServerApplet
    participant NotificationManager
    participant DataAccessor (DB/Memory)
    User->>NotificationCenterPanel: setVisible(true)
    NotificationCenterPanel->>DAppletBridge: bridge.applet().removeExpiredNotifications()
    DAppletBridge->>NotifyServerApplet: removeExpiredNotifications()
    NotifyServerApplet->>NotificationManager: removeExpiredNotifications()
    NotificationManager->>DataAccessor (DB/Memory): removeEntitiesByExpiredTime(cutoffTime)
    DataAccessor (DB/Memory)-->>NotificationManager: expired notifications deleted
    NotificationManager-->>NotifyServerApplet: cleanup complete
    NotifyServerApplet-->>DAppletBridge: cleanup complete
    DAppletBridge-->>NotificationCenterPanel: cleanup complete
Loading

Class diagram for updated notification cleanup API

classDiagram
    class DataAccessor {
        +removeEntitiesByExpiredTime(qint64 expiredTime)
    }
    class DBAccessor {
        +removeEntitiesByExpiredTime(qint64 expiredTime)
    }
    class MemoryAccessor {
        +removeEntitiesByExpiredTime(qint64 expiredTime)
    }
    class NotificationManager {
        +removeExpiredNotifications()
    }
    class NotifyServerApplet {
        +removeExpiredNotifications()
    }
    DataAccessor <|-- DBAccessor
    DataAccessor <|-- MemoryAccessor
    NotificationManager <.. NotifyServerApplet : used by
    DBAccessor <.. NotificationManager : persistence
    MemoryAccessor <.. NotificationManager : persistence
Loading

File-Level Changes

Change Details Files
Refactor data accessor interfaces to support direct deletion of expired entities
  • Removed fetchExpiredEntities methods and overrides from DataAccessor, DBAccessor, MemoryAccessor
  • Added virtual removeEntitiesByExpiredTime to DataAccessor and its implementations
  • Updated DataAccessorProxy to route removeEntitiesByExpiredTime to the underlying source
  • Eliminated per-entity retrieval and sorting logic in database and memory layers
panels/notification/common/dataaccessor.h
panels/notification/common/dataaccessorproxy.h
panels/notification/common/dbaccessor.cpp
panels/notification/common/dbaccessor.h
panels/notification/common/memoryaccessor.cpp
panels/notification/common/memoryaccessor.h
Switch NotificationManager from timer-based to on-demand expired cleanup
  • Removed m_cleanupTimer, its setup and onCleanupExpiredNotifications slot
  • Added removeExpiredNotifications slot to call persistence->removeEntitiesByExpiredTime
  • Replaced periodic deletion logic with a single-shot API that deletes by cutoff time
panels/notification/server/notificationmanager.cpp
panels/notification/server/notificationmanager.h
Integrate on-demand cleanup into UI and D-Bus interface
  • Invoke removeExpiredNotifications via DAppletBridge when notification center becomes visible
  • Expose removeExpiredNotifications slot in NotifyServerApplet
  • Wired UI visibility change to trigger the new cleanup pathway
panels/notification/center/notificationcenterpanel.cpp
panels/notification/server/notifyserverapplet.cpp
panels/notification/server/notifyserverapplet.h

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

@18202781743 18202781743 force-pushed the master branch 3 times, most recently from e85baee to d8c62f2 Compare October 24, 2025 10:22
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个代码变更进行审查:

  1. 代码逻辑和设计变更:
  • 主要变更将过期通知的清理从定时器驱动改为按需触发
  • 移除了原有的定时清理机制(m_cleanupTimer)
  • 新增了removeExpiredNotifications()方法,在通知中心显示时触发清理
  1. 性能优化:
  • 优点:避免了不必要的定时器开销,改为按需清理更高效
  • 优点:直接删除过期通知,而不是先查询再删除,减少了数据库操作
  1. 代码质量改进:
  • 优点:代码结构更清晰,职责划分更明确
  • 建议:NotificationCenterPanel::setVisible中的QMetaObject::invokeMethod调用可以添加错误处理
  1. 安全性考虑:
  • 代码变更本身没有引入新的安全风险
  • 数据库操作都有适当的错误处理
  1. 具体改进建议:
// 在 NotificationCenterPanel::setVisible 中添加错误处理
if (m_visible) {
    qDebug(notifyLog) << "Try to remove expired notifications.";
    DAppletBridge bridge("org.deepin.ds.notificationserver");
    if (auto applet = bridge.applet()) {
        if (!QMetaObject::invokeMethod(applet, "removeExpiredNotifications", Qt::DirectConnection)) {
            qWarning(notifyLog) << "Failed to invoke removeExpiredNotifications";
        }
    } else {
        qWarning(notifyLog) << "Failed to get notification server applet";
    }
}
  1. 其他建议:
  • 考虑在DBAccessor::removeEntitiesByExpiredTime中添加事务处理,确保数据一致性
  • 可以考虑添加清理操作的日志记录,便于问题追踪
  • 建议在MemoryAccessor::removeEntitiesByExpiredTime中添加日志记录删除的通知数量

总体来说,这次变更是一个很好的优化,将定时清理改为按需清理更符合实际需求,代码结构也更加清晰。只需要在错误处理和日志记录方面做一些小的改进。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy, wjyrich

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

Changed the expired notification cleanup mechanism from fetching and
processing expired entities to directly deleting them from storage.
The previous implementation used fetchExpiredEntities to get expired
notifications and then closed them individually, which was inefficient
for large datasets. The new approach adds removeEntitiesByExpiredTime
method that directly deletes expired records from database and memory
storage, improving performance by eliminating unnecessary data retrieval
and processing.

Added trigger to automatically clean expired notifications when
notification center becomes visible, ensuring users always see current
notifications without expired ones cluttering the interface. This on-
demand cleanup approach is more efficient than the previous timer-based
periodic cleanup.

Log: Optimized notification cleanup to remove expired notifications when
opening notification center

Influence:
1. Test opening notification center to verify expired notifications are
automatically removed
2. Verify notification count displays correctly after cleanup
3. Test notification persistence for non-expired notifications
4. Check database storage efficiency after implementing direct deletion
5. Verify memory usage improvement with the optimized cleanup approach
6. Test notification center performance with large number of
notifications

refactor: 优化过期通知清理实现

将过期通知清理机制从获取和处理过期实体改为直接从存储中删除。之前的实现使
用 fetchExpiredEntities 获取过期通知然后逐个关闭,对于大数据集效率低下。
新方法添加了 removeEntitiesByExpiredTime 方法,直接从数据库和内存存储中
删除过期记录,通过消除不必要的数据检索和处理来提高性能。

添加了在通知中心变为可见时自动清理过期通知的触发器,确保用户始终看到当前
通知而不会被过期通知干扰界面。这种按需清理方法比之前的基于定时器的定期清
理更高效。

Log: 优化通知清理功能,在打开通知中心时自动移除过期通知

Influence:
1. 测试打开通知中心验证过期通知是否自动移除
2. 验证清理后通知计数显示是否正确
3. 测试非过期通知的持久化存储
4. 检查实现直接删除后的数据库存储效率
5. 验证优化清理方法后的内存使用改进
6. 测试通知中心在大量通知情况下的性能表现
@18202781743
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Oct 27, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 2a96580 into linuxdeepin:master Oct 27, 2025
8 of 11 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.

4 participants