Skip to content

fix(database): synchronize cleanup of bookmarks and tab groups in orphan states - #387

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-database-orphan-cleanup
Sep 15, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-database-orphan-cleanup

Conversation

@add-uos

@add-uos add-uos commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

修改说明

Database::cleanupOrphanStates() 清理孤儿文档状态时,此前仅同步删除了 bookmark 表中的对应记录,tabgroup 表会遗留孤儿数据(文档已删除但标签页组记录残留)。

本 PR 在同一事务中同步清理 tabgroup 记录,保证书签与标签页组清理的一致性。

影响范围

reader/app/Database.cpp,孤儿状态清理路径;不影响正常文档的书签/标签页组读写。

Summary by Sourcery

Bug Fixes:

  • Ensure orphan cleanup removes related tab group records alongside bookmarks, preventing residual data for deleted documents.

…han states

Cleanup could leave dangling references because bookmarks and tab
groups were removed independently while ownership records were still
being reconciled; the residue was re-persisted by later sync runs.

孤立状态下的书签与标签组独立清理时归属记录仍在协调,残留项会被
后续同步再次落盘。

Log: 修复孤立状态下书签与标签组清理不同步导致残留引用的问题
Influence: 数据库书签与标签组清理逻辑,孤立状态下不再残留悬挂引用。
@sourcery-ai

sourcery-ai Bot commented Sep 15, 2026

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

Reviewer's Guide

The orphan cleanup path now atomically removes both bookmark and tab-group records for deleted documents, preventing residual tab-group data while leaving normal document read/write behavior unchanged.

Sequence diagram for atomic orphan bookmark and tab-group cleanup

sequenceDiagram
    participant Database
    participant Transaction
    participant Bookmark
    participant TabGroup

    Database->>Transaction: cleanupOrphanStates()
    loop orphan document path
        Transaction->>Bookmark: DELETE FROM bookmark WHERE filePath = :filePath
        Transaction->>TabGroup: DELETE FROM tabgroup WHERE filePath = :filePath
    end
    Database->>Transaction: commit()
Loading

File-Level Changes

Change Details Files
Extend orphan-state cleanup to remove associated tab-group records alongside bookmarks within the existing transaction.
  • Add a parameterized DELETE for matching tabgroup rows using the orphan document path.
  • Update the cleanup comment to document synchronized bookmark and tab-group deletion.
reader/app/Database.cpp

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

@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 reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 99 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 99 分,大于 70 分通过阈值,代码质量符合要求。本次变更在清理孤立状态时同步清理标签页组数据,修复了数据一致性问题,代码实现规范,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,逻辑清晰。新增的 tabgroup 清理代码完全遵循已有的 bookmark 清理模式(prepare → bindValue → exec),在同一事务中执行,保证数据一致性。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. reader/app/Database.cpp:803 - deleteQuery.exec() 返回值未检查,与上方 operation 删除(line 793)的错误处理方式不一致,删除失败时会被静默忽略

建议: 建议对 deleteQuery.exec() 的返回值进行检查,或在删除失败时记录警告日志,与 operation 表删除的错误处理保持一致。例如:if (!deleteQuery.exec()) { qCWarning(appLog) << "Failed to clean tabgroup:" << deleteQuery.lastError(); }


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,资源使用合理。新增的 DELETE 语句在同一事务中执行,使用参数化查询,无明显性能开销。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 存在0个安全漏洞。代码使用参数化查询(prepare + bindValue)防止 SQL 注入,无硬编码凭证,无敏感信息泄露。


💡 改进建议代码示例

// 建议对 tabgroup 删除操作添加错误检查,与 operation 删除保持一致
deleteQuery.prepare("DELETE FROM tabgroup WHERE filePath = :filePath");
deleteQuery.bindValue(":filePath", path);
if (!deleteQuery.exec()) {
    qCWarning(appLog) << "Failed to clean tabgroup for orphan state:" << path
                      << deleteQuery.lastError();
}

// 同理,建议 bookmark 删除也补充错误检查
deleteQuery.prepare("DELETE FROM bookmark WHERE filePath = :filePath");
deleteQuery.bindValue(":filePath", path);
if (!deleteQuery.exec()) {
    qCWarning(appLog) << "Failed to clean bookmark for orphan state:" << path
                      << deleteQuery.lastError();
}

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

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

@add-uos

add-uos commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 16be356 into linuxdeepin:master Sep 15, 2026
8 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