-
Notifications
You must be signed in to change notification settings - Fork 55
feat: add notification auto cleanup and timeout handling #1299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| m_systemApps = config->value("systemApps").toStringList(); | ||
| // TODO temporary fix for AppNamesMap | ||
| m_appNamesMap = config->value("AppNamesMap").toMap(); | ||
| m_cleanupDays = config->value("notificationCleanupDays", 7).toInt(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加个有效的检验,
1. Add fetchFirstEntity method to data accessor interfaces for retrieving earliest notifications 2. Implement notification auto-cleanup feature that removes processed notifications older than configured days 3. Add Timeout processed type for handling expired notifications 4. Add configuration option for notification cleanup days with default value of 7 days 5. Implement cleanup timer that runs every second to check for expired notifications 6. Update notification processing to handle timeout closures properly feat: 添加通知自动清理和超时处理功能 1. 在数据访问器接口中添加 fetchFirstEntity 方法用于获取最早的通知 2. 实现通知自动清理功能,删除超过配置天数的已处理通知 3. 添加 Timeout 处理类型用于处理过期通知 4. 添加通知清理天数的配置选项,默认值为7天 5. 实现清理定时器,每秒检查一次过期通知 6. 更新通知处理逻辑以正确处理超时关闭 PMS: BUG-284979
cf283ca to
089a3ef
Compare
deepin pr auto review代码审查报告1. 整体功能这段代码实现了一个通知系统的自动清理功能,主要添加了以下功能:
2. 代码质量评估优点:
需要改进的地方:
3. 代码安全评估
4. 改进建议
// 建议在 MemoryAccessor 中添加按时间索引的容器
QMap<qint64, NotifyEntity> m_entitiesByTime;
// 在 fetchExpiredEntities 中使用二分查找优化
auto it = m_entitiesByTime.upperBound(expiredTime);
expiredEntities.reserve(it - m_entitiesByTime.begin());
for (auto i = m_entitiesByTime.begin(); i != it; ++i) {
expiredEntities.append(i.value());
}
if (config->value("notificationCleanupDays").isValid()) {
m_cleanupDays = qBound(1, config->value("notificationCleanupDays").toInt(), 30); // 限制在1-30天之间
}
if (!query.exec()) {
qWarning(notifyDBLog) << "Query execution error:" << query.lastError().text();
// 可以考虑添加重试逻辑
return {};
}
m_cleanupTimer->setInterval(24 * 60 * 60 * 1000); // 改为每天执行一次
void NotificationManager::onCleanupExpiredNotifications()
{
const qint64 cutoffTime = QDateTime::currentDateTime().addDays(-m_cleanupDays).toMSecsSinceEpoch();
auto expiredEntities = m_persistence->fetchExpiredEntities(cutoffTime);
// 临时禁用信号,防止递归调用
bool wasBlocked = m_blockNotifications;
m_blockNotifications = true;
for (const auto &entity : expiredEntities) {
notificationClosed(entity.id(), entity.bubbleId(), NotifyEntity::Timeout);
}
m_blockNotifications = wasBlocked;
}5. 总结整体实现思路清晰,功能完整,但在性能优化和错误处理方面还有改进空间。建议按照上述建议进行优化,特别是在处理大量通知时的性能表现和错误恢复机制。同时,建议添加单元测试来验证新功能的正确性和稳定性。 |
| m_appNamesMap = config->value("AppNamesMap").toMap(); | ||
|
|
||
| if(!config->value("notificationCleanupDays").isNull()) { | ||
| m_cleanupDays = config->value("notificationCleanupDays").toInt(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个时间,可能是个无效的,
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, wjyrich The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
TAG Bot New tag: 2.0.14 |
|
/forcemerge |
|
This pr force merged! (status: behind) |
feat: 添加通知自动清理和超时处理功能
PMS: BUG-284979