Skip to content

feat(database): match state by document identifier and flush to disk - #344

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:style-widget-restoreTip
Aug 27, 2026
Merged

feat(database): match state by document identifier and flush to disk#344
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:style-widget-restoreTip

Conversation

@add-uos

@add-uos add-uos commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Extract PDF /ID as a stable document identifier and use it to match saved reading state after rename/move. Add Database::flushToDisk and fsync on PDF save for crash durability.

提取 PDF /ID 作为稳定文档标识,用于改名/移动后匹配阅读状态;
新增 Database::flushToDisk 及 PDF 保存 fsync,提升崩溃持久性。

Log: 按文档标识匹配阅读状态并增加刷盘持久化
PMS: BUG-390571
Influence: 文件改名/移动后仍能恢复阅读状态;书签与进度保存更可靠。

Summary by Sourcery

Preserve document state across file relocation and strengthen persistence against crashes.

New Features:

  • Match saved reading state and bookmarks using a PDF’s stable document identifier so they survive file renames and moves.
  • Expose database flushing to disk for durable persistence of critical reader state.

Bug Fixes:

  • Preserve saved state for files moved on removable media by avoiding premature orphan cleanup and using stronger content matching fallback.

Enhancements:

  • Improve crash durability with WAL, full synchronous database commits, explicit database fsync, and fsync after PDF saves.

Extract PDF /ID as a stable document identifier and use it to match
saved reading state after rename/move. Add Database::flushToDisk and
fsync on PDF save for crash durability.

提取 PDF /ID 作为稳定文档标识,用于改名/移动后匹配阅读状态;
新增 Database::flushToDisk 及 PDF 保存 fsync,提升崩溃持久性。

Log: 按文档标识匹配阅读状态并增加刷盘持久化
PMS: BUG-390571
Influence: 文件改名/移动后仍能恢复阅读状态;书签与进度保存更可靠。

@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.

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 1 hour by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR adds stable PDF /ID-based reading-state recovery across renames and moves, with content-hash fallback and bookmark/path migration, while improving persistence durability through PDF fsync, SQLite WAL/FULL synchronization, and an explicit database flush API.

Sequence diagram for document state recovery after rename or move

sequenceDiagram
    participant File as PDF file
    participant Renderer as SheetRenderer
    participant PDF as PDFDocument
    participant DB as Database

    File->>Renderer: fileIdentifier()
    Renderer->>PDF: fileIdentifier()
    PDF-->>Renderer: permanent PDF /ID
    Renderer-->>DB: docId
    DB->>DB: SELECT operation WHERE docId = :docId
    alt docId match
        DB->>DB: load saved reading state
        DB->>DB: UPDATE operation filePath
        DB->>DB: UPDATE bookmark filePath
    else no docId match
        DB->>DB: computeContentHash(filePath)
        DB->>DB: SELECT operation WHERE fileSize = :fileSize AND contentHash = :contentHash
    end
Loading

File-Level Changes

Change Details Files
Expose the PDF trailer’s permanent /ID through the document abstraction and persist it with reading-operation state.
  • Add a PDFium identifier extractor that returns the permanent ID as hexadecimal.
  • Propagate identifier access through Document, PDFDocument, and SheetRenderer.
  • Add and migrate the operation-table docId column, and save it with state records.
3rdparty/deepin-pdfium/include/dpdfdoc.h
3rdparty/deepin-pdfium/src/dpdfdoc.cpp
reader/document/Model.h
reader/document/PDFModel.h
reader/document/PDFModel.cpp
reader/uiframe/SheetRenderer.h
reader/uiframe/SheetRenderer.cpp
reader/app/Database.h
reader/app/Database.cpp
Rework state recovery to prefer document identity while retaining content-based fallback and synchronizing moved paths.
  • Match operation rows by docId first and choose the most recently modified duplicate.
  • Fall back to file size plus head-and-tail content hash without relying on mtime.
  • Restore operation state and update both operation and bookmark paths in one transaction.
  • Preserve states for paths under common removable-media mount points during orphan cleanup.
reader/app/Database.cpp
Improve crash durability for PDF and database persistence.
  • Flush and fsync PDF save output before closing the file.
  • Switch SQLite to WAL journaling with FULL synchronous mode.
  • Add flushToDisk to checkpoint and truncate the WAL, then fsync the database file.
3rdparty/deepin-pdfium/src/dpdfdoc.cpp
reader/app/Database.h
reader/app/Database.cpp
Strengthen the legacy content fingerprint used when no document identifier is available.
  • Hash both the first and last 64 KiB with SHA-256 to reduce collisions from shared PDF headers.
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

@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 Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 08c6929 into linuxdeepin:master Aug 27, 2026
8 of 9 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