Skip to content

uploads: finish whole-file uploads sooner, save picked photos off the main thread, keep album order after relaunch - #166

Closed
morajabi wants to merge 4 commits into
mainfrom
transfers-next
Closed

morajabi wants to merge 4 commits into
mainfrom
transfers-next

Conversation

@morajabi

Copy link
Copy Markdown
Contributor

Upload speedups from the Nov 19 transfers slice, rebased onto current main. No protocol or schema change.

Server: whole-file uploads finish sooner

A file sent whole with create used to be written to staging, written again to its final key after finish, and have its fresh 30 s lease renewed four times before publishing.

  • The final-object write starts alongside the staging write (the client can't cancel before it learns the upload id); the worker skips it when that write succeeded.
  • The stripped photo thumbnail is made while the file is written.
  • Ownership checks within 5 s of a confirmed lease skip the database. The heartbeat still renews it, and publishing still requires the lock token.
  • TRANSFER_TRACE gains putMs, the summed storage write time.

Server: races around the early write

  • A claim that fails before its own write (for example a thumbnail that doesn't resolve) waits for the early write before cleanup, so the write can't land after the key is deleted.
  • Create's reply no longer waits out the 60 s storage deadline after a finish timeout or a fast staging failure.
  • A repeated create on an expired, not-yet-cleaned row no longer leaves a key with no row; expiry cleanup removes a key left by a cancel racing a retried create.

iOS: picking photos no longer blocks the main thread

Picked, pasted and previewed photos are encoded, written and saved off the main actor, two at a time to bound memory, in order. The preview closes right away; the message sends once the photo is saved.

Apple: albums keep their order after a relaunch

Sends made together shared a millisecond timestamp, so resumed interrupted sends could reorder. Sends are spaced 1 ms apart, and recovery breaks date ties by insertion order.

Rebase notes

Conflicts with file albums (1a32bfb) in AlbumSend.swift and MessageAlbumsTests.swift: kept main's albumSendRuns and its assertion that a document joins the album, and added the date spacing plus a millisecond-order check.

Tests (local)

  • Server src/modules/uploads: 99 pass; src/modules/transfers: 2 pass (local Postgres)
  • InlineKit MessageAlbums|PendingSendRecovery|AlbumSend: 18 pass

Server changes reach production only on the next deploy; the deploy gate runs the uploads smoke test.

…photo media work alongside the write, skip lease renewals moments after a claim, reuse the create owner in finish, and trace put time

A whole file sent with create was written to staging, then to its final key after finish, then
renewed its fresh 30 s lease four times before publishing. The final write now starts with
staging (the client cannot cancel before it learns the upload id), the worker skips it when that
write succeeded, the stripped thumbnail runs alongside the write, and ownership checks within
5 s of a confirmed lease skip the database (the heartbeat still renews; the publish stays
conditional on the lock token). TRANSFER_TRACE gains putMs, the summed storage write time.
…pted sends in insertion order, so an album keeps its order after a relaunch
…o at a time, and close the preview before the send
…p, stop it when create replies, and skip it near expiry

Review of the early final-object write: a claim that failed before its own write (a thumbnail
that does not resolve) removed the key while the early write could still land after it; create's
reply could wait out the 60 s storage deadline after a finish timeout or a fast staging failure;
and a repeated create on an expired, not yet cleaned row could leave a key with no row to remove
it. A retried create also reveals the upload id while the first request's write runs, so a cancel
can race it; expiry cleanup removes a key left that way.
@morajabi

Copy link
Copy Markdown
Contributor Author

Landed the server commits (055bba8, 35ab737) and the shared Apple album-order fix (1b2c394) on main. The iOS picker commit moves into #164: its photo preparation now holds a pending tile before it starts, so a send waits for it instead of going out as text alone and leaving the photo in the next draft, and it prepares two photos at a time. Closing this PR.

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