fix: clear update logs to prevent duplicate entries#301
Conversation
The previous implementation did not clear the security and system log containers before appending new log data. This caused duplicate log entries to accumulate when the update log data was refreshed, resulting in repeated display of update information each time the logs were processed. Added appropriate clearing mechanisms: 1. Clear m_securityLog before processing security log entries 2. Clear itemInfo's current version and detail infos before processing system item info 3. Add clearDetailInfos() method to UpdateItemInfo for consistent detail info management Log: Fixed duplicate update log entries issue Influence: 1. Test update log display after system updates 2. Verify that log entries do not duplicate when refreshing update information 3. Check that security update logs show correctly without repeated entries 4. Verify item info version and details are properly reset before new data is filled 5. Test multiple update cycles to ensure logs remain clean fix: 修复更新日志重复问题 之前的实现没有在追加新的日志数据前清空安全日志和系统日志容器,导致每次处 理记录时,日志条目累加,更新信息重复显示。增加了相应的清理机制: 1. 处理安全日志条目前清空 m_securityLog 2. 处理系统项目信息前清空 itemInfo 的当前版本和详细信息 3. 在 UpdateItemInfo 中添加 clearDetailInfos() 方法确保详细信息一致性 管理 Log: 修复了更新日志重复显示的问题 Influence: 1. 测试系统更新后更新日志的显示情况 2. 验证刷新更新信息时日志条目不会重复 3. 检查安全更新日志是否正确显示,没有重复条目 4. 验证新数据填充前项目信息版本和详情正确重置 5. 测试多个更新周期确保日志保持清晰 PMS: BUG-362665 Change-Id: I2cbdf3016e3a35c0e805aa6008f5b4bf293f823b
deepin pr auto review你好!我是CodeGeeX,你的智能编程助手。我已经仔细审查了你提供的Git Diff代码。这次修改主要是在 整体来看,代码逻辑清晰,修改目的明确。不过,为了进一步提升代码的语法逻辑、代码质量、代码性能和代码安全性,我提出以下改进建议: 1. 语法与逻辑问题:
问题:
2. 代码质量建议:为 修改前: void UpdateItemInfo::clearDetailInfos()
{
m_detailInfos.clear();
}修改后: void UpdateItemInfo::clearDetailInfos()
{
qCDebug(logDccUpdatePlugin) << "Clearing detail infos for item:" << m_name;
m_detailInfos.clear();
}3. 代码性能问题: qCDebug(logDccUpdatePlugin) << "Handling security log with" << log.keys().size() << "entries";
m_securityLog.clear();
for (const auto& key : log.keys()) {
优化后代码: void UpdateLogHelper::handleSecurity(const QJsonObject &log)
{
const QStringList keys = log.keys(); // 使用 const 引用或局部常量避免重复计算和拷贝
qCDebug(logDccUpdatePlugin) << "Handling security log with" << keys.size() << "entries";
m_securityLog.clear();
// 如果能预估大小,可以 m_securityLog.reserve(keys.size());
for (const auto& key : keys) {
const auto& obj = log.value(key).toObject();
if (obj.isEmpty())
continue;
// ...
}
}或者更高效地使用 void UpdateLogHelper::handleSecurity(const QJsonObject &log)
{
qCDebug(logDccUpdatePlugin) << "Handling security log with" << log.size() << "entries";
m_securityLog.clear();
for (auto it = log.constBegin(); it != log.constEnd(); ++it) {
const auto& obj = it.value().toObject();
if (obj.isEmpty())
continue;
// 使用 it.key() 获取 key
}
}4. 代码安全问题:空指针解引用风险
修改后代码(以 void UpdateLogHelper::handleSystemItemInfo(UpdateItemInfo *itemInfo) const
{
if (!itemInfo) {
qCWarning(logDccUpdatePlugin) << "handleSystemItemInfo: itemInfo is null";
return;
}
if (m_systemLog.isEmpty()) {
return;
}
itemInfo->setCurrentVersion("");
itemInfo->clearDetailInfos();
// ...
}总结你的代码修改很好地解决了数据未清空导致的残留Bug,方向完全正确。建议按照上述意见进行微调,重点关注**空指针防御(安全性)和 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy, xionglinlin The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
The previous implementation did not clear the security and system log containers before appending new log data. This caused duplicate log entries to accumulate when the update log data was refreshed, resulting in repeated display of update information each time the logs were processed. Added appropriate clearing mechanisms:
Log: Fixed duplicate update log entries issue
Influence:
fix: 修复更新日志重复问题
之前的实现没有在追加新的日志数据前清空安全日志和系统日志容器,导致每次处
理记录时,日志条目累加,更新信息重复显示。增加了相应的清理机制:
Log: 修复了更新日志重复显示的问题
Influence:
PMS: BUG-362665
Change-Id: I2cbdf3016e3a35c0e805aa6008f5b4bf293f823b