Skip to content

feat(sync): add delay sync for growing files#39

Open
CrooLyyCheck wants to merge 1 commit intocloudreve:mainfrom
CrooLyyCheck:feat/delay-sync
Open

feat(sync): add delay sync for growing files#39
CrooLyyCheck wants to merge 1 commit intocloudreve:mainfrom
CrooLyyCheck:feat/delay-sync

Conversation

@CrooLyyCheck
Copy link
Copy Markdown

@CrooLyyCheck CrooLyyCheck commented Mar 31, 2026

Note ⚠️

Hi, I just vibe-coded the whole thing, almost end-to-end, including cloning the repo, forking it, and pushing this PR. So please don’t take this PR too seriously, only like a feature request/proof of concept. I don’t have much experience writing code on my own. I only have a basic understanding of what some code fragments do. Video without and with this feature enabled: https://youtu.be/iApYUjTPDPA

Problem

When large media files (for example, a 4-minute screen recording) are saved directly inside a synced folder, the .mp4 file keeps growing while recording is still in progress. The current sync flow may enqueue upload too early, which can result in uploading an incomplete file revision, unnecessary re-uploads, and wasted bandwidth.

Root Cause

Upload tasks are triggered on local file create/modify events. For continuously written files, these events happen before the producing process closes the file and before content stabilizes.

What This PR Introduces

1) New user-facing setting (General -> Experimental features)

  • Adds a new Experimental features section in General settings.
  • Section title is styled in red as requested.
  • Adds Delay sync as a select/dropdown option (same interaction model as Max log files).
  • Options:
    • off
    • 10s
    • 30s
    • 1min
    • 2min
    • 5min
  • Description: Sync task wait until file stop changing.

2) Persisted configuration and Tauri command wiring

  • Adds persisted config field: sync_delay_seconds in AppConfig.
  • Default is 0 (feature disabled by default, preserving current behavior).
  • Exposes getter/setter in ConfigManager.
  • Extends get_general_settings payload with sync_delay_seconds.
  • Adds new command: set_sync_delay_seconds.

3) Upload queue stabilization logic

Before executing an upload task, queue now:

  • Reads configured delay from ConfigManager.
  • If delay is 0, proceeds immediately (backward-compatible behavior).
  • If delay > 0, waits until file remains unchanged for the configured window.
  • Uses lightweight file-change signature:
    • file size
    • last modified timestamp
  • Resets stability timer whenever signature changes.
  • Handles cancellation while waiting (queue shutdown/task cancellation respected).
  • Skips waiting for non-file/missing paths.

4) Performance safeguards

To minimize machine load while waiting:

  • No busy-wait; loop sleeps between checks.
  • Adaptive polling interval:
    • 1s for short delays
    • 2s for medium delays
    • 3s for long delays
  • Task status DB checks throttled to every 5s during wait.

Why This Solves the Problem

For long-running writers (screen recording, video export, etc.), upload starts only after the file has stopped changing for the selected stability window. This prevents premature upload of in-progress files and reduces unnecessary network and sync churn.

Backward Compatibility

  • Default setting is off (sync_delay_seconds = 0).
  • Existing users keep current sync behavior unless they explicitly enable Delay sync.

Scope of Changes

  • UI settings: new section + Delay sync select + locale strings.
  • Tauri IPC layer: new command and extended settings payload.
  • Sync core: configurable delayed upload start with low-overhead stability checks.

Test Plan

  • Set Delay sync to 30s.
  • Start recording a long .mp4 directly inside synced folder.
  • Verify upload does not start while file keeps growing.
  • Stop recording and verify upload starts only after ~30s of no changes.
  • Repeat with off and verify immediate upload behavior is unchanged.
  • Restart app and verify chosen Delay sync value persists.

Add a delay sync setting so uploads wait until files stop changing, preventing partial uploads for growing files like in-progress video recordings.

Made-with: Cursor
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 31, 2026

CLA assistant check
All committers have signed the CLA.

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