Skip to content

Persist attachment state per record during sync passes#3

Merged
austinbhale merged 3 commits into
mainfrom
fix/persist-attachment-state-per-record
Jun 10, 2026
Merged

Persist attachment state per record during sync passes#3
austinbhale merged 3 commits into
mainfrom
fix/persist-attachment-state-per-record

Conversation

@austinbhale

Copy link
Copy Markdown
Member

RunSyncPassAsync held the attachment context mutex for the entire pass and saved all state changes in one batch at the end. On a large queue, a single pass starved every other queue operation for its duration, plus any interruption discarded the progress of every completed transfer.

The context is now acquired only for table reads and writes, and each attachment is persisted as soon as its transfer completes, matching the JS & Dart helpers.

Copilot AI 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.

Pull request overview

This PR reduces attachment-sync contention by avoiding holding the attachment context mutex for an entire sync pass, and by persisting progress incrementally (per attachment) so completed transfers aren’t lost on interruption.

Changes:

  • Add a pass-level lock and refactor RunSyncPassAsync to acquire the attachment context only for specific reads/writes.
  • Update attachment processing to persist each state change immediately after its transfer completes.
  • Thread cancellation through SyncStorageAsync / RunSyncPassAsync so cancellation is observed between records.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
PowerSync/PowerSync.Common/Attachments/SyncingService.cs Refactors sync pass execution and per-attachment persistence to reduce long mutex holds and improve progress durability.
PowerSync/PowerSync.Common/Attachments/AttachmentQueue.cs Plumbs a CancellationToken through the public API for running an on-demand sync pass.

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

Comment thread PowerSync/PowerSync.Common/Attachments/SyncingService.cs Outdated
Comment thread PowerSync/PowerSync.Common/Attachments/SyncingService.cs
@austinbhale austinbhale merged commit 266dd10 into main Jun 10, 2026
2 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.

2 participants