-
Notifications
You must be signed in to change notification settings - Fork 58
fix: correct notification ID handling and validation #1417
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
1. Fixed BubbleModel to use entity id instead of bubble id for data retrieval 2. Updated BubblePanel to check for InvalidId (0) instead of id > 0 when closing bubbles 3. Modified DataAccessorProxy to return empty entity instead of cascading fetch when primary source fails 4. Changed MemoryAccessor to generate unique negative IDs for in-memory entities to avoid conflicts 5. Updated NotifyEntity to use InvalidId constant (0) instead of -1 for invalid state 6. Added InvalidId constant definition in NotifyEntity header 7. Fixed NotificationManager to properly handle replace operations and return false when replace fails 8. Ensured consistent ID validation across all components using InvalidId constant Log: Fixed notification display issues where incorrect IDs caused mismatched notifications Influence: 1. Test notification display in bubble panel with various notification types 2. Verify bubble closing functionality works correctly 3. Test notification replacement scenarios 4. Check memory-only notification handling 5. Validate notification persistence and retrieval from database 6. Test edge cases with invalid notification IDs 7. Verify notification matching and display consistency fix: 修正通知ID处理和验证逻辑 1. 修复BubbleModel使用实体ID而非气泡ID进行数据检索 2. 更新BubblePanel在关闭气泡时检查InvalidId(0)而非id>0 3. 修改DataAccessorProxy在主数据源失败时返回空实体而非级联查询 4. 更改MemoryAccessor为内存实体生成唯一的负ID以避免冲突 5. 更新NotifyEntity使用InvalidId常量(0)而非-1表示无效状态 6. 在NotifyEntity头文件中添加InvalidId常量定义 7. 修复NotificationManager正确处理替换操作并在替换失败时返回false 8. 确保所有组件使用InvalidId常量进行一致的ID验证 Log: 修复通知显示问题,错误的ID导致通知匹配混乱 Influence: 1. 测试气泡面板中各种通知类型的显示 2. 验证气泡关闭功能正常工作 3. 测试通知替换场景 4. 检查仅内存通知的处理 5. 验证通知持久化和从数据库检索 6. 测试无效通知ID的边缘情况 7. 验证通知匹配和显示一致性 PMS: BUG-349053
deepin pr auto review这份代码修改主要涉及通知系统中 ID 的处理逻辑,将原本基于 以下是对各部分代码的详细审查意见: 1. 整体逻辑与设计优点:
潜在问题:
2. 文件具体审查
|
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.
Hey - I've found 1 issue, and left some high level feedback:
- In MemoryAccessor::addEntity, the static local g_Id is shared across all MemoryAccessor instances and updated without its own synchronization; consider making it a member variable (initialized once per accessor) protected by m_mutex to avoid cross-instance coupling and potential race conditions if addEntity is ever called concurrently across instances.
- Now that in-memory entities intentionally use negative IDs and persistent ones use positive IDs, it may be worth enforcing this invariant at the boundaries (e.g., in addEntity/replaceEntity or NotifyEntity construction) to catch incorrect ID assignments early rather than relying only on InvalidId checks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In MemoryAccessor::addEntity, the static local g_Id is shared across all MemoryAccessor instances and updated without its own synchronization; consider making it a member variable (initialized once per accessor) protected by m_mutex to avoid cross-instance coupling and potential race conditions if addEntity is ever called concurrently across instances.
- Now that in-memory entities intentionally use negative IDs and persistent ones use positive IDs, it may be worth enforcing this invariant at the boundaries (e.g., in addEntity/replaceEntity or NotifyEntity construction) to catch incorrect ID assignments early rather than relying only on InvalidId checks.
## Individual Comments
### Comment 1
<location> `panels/notification/common/memoryaccessor.cpp:18-21` </location>
<code_context>
qint64 MemoryAccessor::addEntity(const NotifyEntity &entity)
{
+ static qint64 g_Id = NotifyEntity::InvalidId; // use negative id for in-memory entities
QMutexLocker locker(&m_mutex);
m_entities << entity;
- return entity.bubbleId();
+ return --g_Id;
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Consider updating the stored entity's id to match the generated in-memory id.
In `addEntity`, we store `entity` unchanged but return a decremented `g_Id`. Unless `NotifyEntity` is updated elsewhere, `entity.id()` will stay `InvalidId` while callers may rely on the returned negative id. Any code that later uses `entity.id()` (e.g., for comparisons or lookups) will then see a different id than the one returned here. Consider cloning/updating the entity with the generated id before storing it so the stored entity and returned id are consistent.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| static qint64 g_Id = NotifyEntity::InvalidId; // use negative id for in-memory entities | ||
| QMutexLocker locker(&m_mutex); | ||
| m_entities << entity; | ||
| return entity.bubbleId(); | ||
| return --g_Id; |
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.
issue (bug_risk): Consider updating the stored entity's id to match the generated in-memory id.
In addEntity, we store entity unchanged but return a decremented g_Id. Unless NotifyEntity is updated elsewhere, entity.id() will stay InvalidId while callers may rely on the returned negative id. Any code that later uses entity.id() (e.g., for comparisons or lookups) will then see a different id than the one returned here. Consider cloning/updating the entity with the generated id before storing it so the stored entity and returned id are consistent.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, yixinshark 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 |
retrieval
closing bubbles
cascading fetch when primary source fails
entities to avoid conflicts
invalid state
return false when replace fails
InvalidId constant
Log: Fixed notification display issues where incorrect IDs caused
mismatched notifications
Influence:
types
fix: 修正通知ID处理和验证逻辑
Log: 修复通知显示问题,错误的ID导致通知匹配混乱
Influence:
PMS: BUG-349053
Summary by Sourcery
Standardize notification ID handling and invalid ID semantics across notification storage, in-memory access, and UI bubbles to fix mismatched and failing notification operations.
Bug Fixes:
Enhancements: