Repository navigation
fix: background upload discovery and queue blocking - #4525
Merged
Merged
Conversation
With "all photos" enabled the discovery has no date filter, so every background pass walks the library from its oldest asset and ran one GRDB query plus one Realm read for each already uploaded asset. On large libraries this could exhaust the extension's background time before any new photo was queued. Assisted-by: Claude Code:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
Glyphs such as "_" draw ink past their advance, but the natural size counted only the advance. A label sized to its intrinsic width clipped the end of an extension like ".EX_", which also made the NCFilenameUILabel "A name that fits is drawn in full" test fail. Assisted-by: Claude Code:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
Job creation reads only the oldest pending transfers that fit the free PhotoKit slots. Transfers that were skipped on every pass, because they were cancelled before getting a job, had lost their history row or could not build a valid request, stayed at the head of that list and kept newer photos from being uploaded. Assisted-by: Claude Code:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
Discarding a background upload in Transfers removed only its metadata. The upload history still listed the file as not uploaded, so the next discovery pass queued it again. A file that always fails came back after every discard and could not be dismissed. Force Reupload starts a new history session, so it still gives a discarded file new attempts. Assisted-by: Claude Code:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
- Count a retry before PhotoKit can start it. The count was saved after the request, so an extension stopped in between allowed one upload more than the three-attempt limit. - Omit X-OC-CTime and X-OC-MTime for dates of one day or less after the epoch. Nextcloud rejects them after writing the file, which wasted an attempt for photos with a camera clock reset to 1970 and failed every attempt with Force Reupload. - Clear the cancellation request when a cancelled upload had already completed, as the host app does, so the kept file carries no stale request. Assisted-by: Claude Code:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
The same steps were written in several places: recording a confirmed upload, deciding what a failed upload means for the account, handling orphan jobs, reading the PhotoKit queues, naming job states and picking the asset resource. Copies that drift apart are hard to read and easy to fix in one place only. Behavior is unchanged, except that a job becoming orphaned during a pass is now acknowledged on the next pass. Assisted-by: Claude Code:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes from a review of the experimental Photos background upload extension (
BackgroundUploadExtension, iOS 27+), plus a small filename label fix found while running the unit tests.Background upload
Discovery no longer reads the history once per uploaded photo. With "all photos" enabled there is no date filter, so every background pass walks the library from its oldest asset. Each already uploaded asset cost one GRDB query and one Realm read, which on large libraries could use up the extension's background time before any new photo was queued. The uploaded components are now read once per pass (
NCLocalDatabase.uploadedAutoUploadClasses) and completed assets are skipped without a query. Assets that are not complete still go through the existing per-asset check.Pending transfers no longer block the queue. Job creation reads only the oldest pending transfers that fit the free PhotoKit slots. Transfers skipped on every pass stayed at the head of that list and kept newer photos waiting. Now:
Discarded uploads are not queued again. Discarding a background upload in Transfers removed only its metadata, while the upload history still listed the file as not uploaded, so the next discovery pass queued it again. A file that always fails came back after every discard. The discarded component is now marked as handled in the history. Force Reupload starts a new history session, so it still gives the file new attempts.
Smaller hardening (one commit).
X-OC-CTime/X-OC-MTimeare omitted for dates of one day or less after the epoch. Nextcloud rejects them only after writing the file, which wasted an attempt for photos with a camera clock reset to 1970.Less duplicated code (refactor commit). Recording a confirmed upload, classifying a failed upload, handling orphan jobs, reading the PhotoKit queues, naming job states and picking the asset resource were each written in two or more places; each now lives in one. Behavior is unchanged, except that a job becoming orphaned during a pass is acknowledged on the next pass.
The legacy auto upload is not affected: it returns early whenever the extension is enabled, and the new history read is used only by the extension.
Filename label (separate commit)
_draws about 0.3 pt past its advance, so a label sized to its intrinsic width clipped the end of an extension like.EX_. This is what made theNCFilenameUILabeltest "A name that fits is drawn in full" fail locally.Testing
Built the
BackgroundUploadExtensionscheme and ranNextcloudUnitTestslocally on the iPhone Duo simulator: all 234 tests pass. The background upload changes were not run on a device or against a live Nextcloud instance.Suggested checks on an iPhone with iOS 27, on a live Nextcloud instance:
_(for exampleSETUP.EX_) show their full extension in the file list.🤖 AI (if applicable)
🤖 Generated with Claude Code