plane icon indicating copy to clipboard operation
plane copied to clipboard

[WIKI-852] chore: update page version save logic

Open NarayanBavisetti opened this issue 1 week ago • 2 comments

Description

This pull request updates the logic for saving page versions.

A new version is created whenever a user starts editing a page. If the same user continues editing actively, all edits made within the next 10 minutes are saved to the same version. Once the 10-minute window passes, a new version is created. If a different user edits the page, a separate version is created for that user. We also retain only the latest 20 versions of a page and older versions beyond that limit are removed.

Blank diagram

Type of Change


[!NOTE] Page versioning improvements

  • Replace page_version task with track_page_version, adding a 10‑minute coalescing window to update the latest PageVersion for the same user instead of creating duplicates
  • Ensure PagesDescriptionViewSet.partial_update captures old_description_html before save for accurate page_transaction and version comparisons
  • Persist version fields consistently (HTML, binary, JSON, stripped, sub_pages_data) and cap history at 20 entries

Written by Cursor Bugbot for commit aece92183da9dff3fe7e88e9c2c14559a7e496ad. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • Page edits now correctly preserve the prior description during updates and return a clear success confirmation after partial saves.
  • New Features

    • Version history now consolidates multiple edits made within a 10-minute window to reduce duplicate entries.

✏️ Tip: You can customize this high-level summary in your review settings.

NarayanBavisetti avatar Dec 23 '25 14:12 NarayanBavisetti

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

makeplane[bot] avatar Dec 23 '25 14:12 makeplane[bot]

[!NOTE]

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Renames the page-version background task to track_page_version, stores the old page HTML in the view before partial updates, and enqueues a background task that either updates a recent PageVersion in-place (if same user and within timeout) or creates a new PageVersion; pruning remains (max 20 versions).

Changes

Cohort / File(s) Summary
View layer
apps/api/plane/app/views/page/base.py
Import changed from page_versiontrack_page_version. Store old_description_html before updates; construct existing_instance using the stored old HTML; call serializer.save() before side effects; enqueue background task with page_id and existing_instance and return updated success.
Background task (versioning)
apps/api/plane/bgtasks/page_version_task.py
Function renamed page_versiontrack_page_version. Added PAGE_VERSION_TASK_TIMEOUT = 600 and timezone import. If description changed, update latest PageVersion in-place when same user and within timeout (update description fields, sub_pages_data, timestamps); otherwise create a new PageVersion. Keep pruning to 20 versions and existing exception handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant View as PageView (partial_update)
    participant Serializer
    participant BG as track_page_version task
    participant DB as PageVersion table

    Client->>View: PATCH page (partial_update)
    View->>View: store old_description_html
    View->>Serializer: validate & serializer.save()
    Serializer-->>View: saved page instance (page_id)
    View->>BG: enqueue track_page_version(page_id, existing_instance, user_id)
    Note right of BG: background worker executes later
    BG->>DB: query latest PageVersion for page_id
    alt latest exists && same user && within timeout
        BG->>DB: update latest PageVersion in-place (description fields, sub_pages_data, updated_at)
    else
        BG->>DB: create new PageVersion record (with last_saved_at = now)
    end
    BG->>DB: prune to max 20 versions for page_id

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I saved the old HTML before the hop,
Sent a task to track each tiny stop.
If you scribble twice within ten, I mend—
Else I birth a version and softly tend.
Thump-thump, versions pruned—onward we hop! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: updating page version save logic, which aligns with the substantial modifications to versioning behavior in both the API view and background task.
Description check ✅ Passed The PR description provides a clear explanation of the versioning changes and includes a diagram. It covers the 10-minute coalescing window, version creation logic, user-specific versioning, and the 20-version limit.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch chore-page-versioning-changes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Dec 23 '25 14:12 coderabbitai[bot]