Skip to content

fix: high CPU usage when deleting collection#498

Open
fishyy119 wants to merge 1 commit intoximu3:mainfrom
fishyy119:fix/delete-collection
Open

fix: high CPU usage when deleting collection#498
fishyy119 wants to merge 1 commit intoximu3:mainfrom
fishyy119:fix/delete-collection

Conversation

@fishyy119
Copy link
Contributor

在删除某个收藏后,CPU会出现持续的高占用。这主要是因为收藏的删除逻辑使用 upsert 方法将文档值设为 {_deleta: true} 来删除文档,这会触发 PouchDB 内部的冲突,产生无限重试,进而导致持续的高 CPU 占用。

本提交将删除逻辑替换为使用remove方法,以解决该问题。

Previously, deleting a document by setting its value to '_delete'
inside db.upsert caused repeated retries, leading to excessive CPU usage.
This occurred because upsert internally retries on conflicts, and returning
the {_deleted: true} flag triggered repeated conflict resolution loops.

This commit moves deletion logic out of upsert into a dedicated removeDoc
method, bypassing the retry loop and eliminating unnecessary CPU load.
The behavior for full-document replacements (#all) and partial updates
remains unchanged.
Copilot AI review requested due to automatic review settings February 13, 2026 06:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical high CPU usage issue that occurs when deleting collections. The problem was caused by using PouchDB's upsert method with {_deleted: true} to delete documents, which triggered internal conflicts in PouchDB leading to infinite retry loops and sustained high CPU usage. The fix replaces this approach with a proper call to the removeDoc method that uses PouchDB's native db.remove() API.

Changes:

  • Refactored document deletion logic to use removeDoc() method instead of upsert with _deleted: true
  • Reorganized imports alphabetically for better code organization
  • Removed problematic deletion logic from within the upsert callback

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

1 participant