Skip to content

Reuse stored metadata when finalizing native uploads - #14707

Merged
loks0n merged 3 commits into
mainfrom
codex/storage-upload-list-performance
Oct 21, 2026
Merged

loks0n merged 3 commits into
mainfrom
codex/storage-upload-list-performance

Conversation

@loks0n

@loks0n loks0n commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Native file uploads fetch MIME type, signature and size through separate object-store metadata requests, including another size lookup after writing transformed bytes. On NYC Spaces each measured HEAD took about 29 ms.

Reuse one FileInfo snapshot for upload finalization. Extend the existing optional metadata with MIME type, normalize optional S3 content types (missing/blank values remain null; parameters and whitespace are removed), retain legacy-device fallbacks, refresh the snapshot after stripping image metadata, and use the known transformed byte length after compression/encryption. Locks, permissions, transform order and stored representations stay intact.

Validation:

  • Storage unit suite: 177 tests / 651 assertions. All four added optional-content-type cases were observed red before the fix and green afterward. Local/S3 MIME regressions observed red before the implementation and green afterward.
  • Targeted PHPStan/Pint, storage package Rector/Pint/PHPStan, monorepo validation and diff checks pass.
  • Isolated NYC backend-stage A/B with 1 MiB payloads and encryption:339.56 → 278.52 ms median, 8 rounds each. Every stored ciphertext was decrypted and checked against the original SHA-256. Temporary backend objects were deleted in finally blocks.
  • This A/B executes separate diagnostic PHP processes; it does not replace serving classes or deploy the candidate endpoint. It is not an end-to-end candidate production benchmark. Existing Storage E2E exercises encryption/compression/signature/size and multipart behavior; no local full API E2E stack was run. CI must confirm that seam before merge.

Production deployments are paused. No Cloud dependency update, release or deployment is part of this PR. Separate files-sdk pagination work addresses the measured listing round trips.

Refs https://github.com/appwrite-labs/cloud/issues/6704

@loks0n loks0n self-assigned this Oct 20, 2026
@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → codex/storage-upload-list-performance (after).

Metric Before After Change
🚀 Requests/sec 195.38 194.36 ⚪ -0.5%
⏱️ Latency P50 87.71 ms 89.24 ms ⚪ +1.7%
⏱️ Latency P95 209.71 ms 206.6 ms ⚪ -1.5%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 89.24 206.6 12,426 194.36 -3.11
Account 163.09 312.83 654 10.86 -1.44
TablesDB 87.23 168.44 6,758 108.52 -3.45
Storage 79.66 185.88 3,270 54.38 -2.76
Functions 125.95 235.61 1,744 29.64 -6.78

Top API waits (after)

API request Max wait (ms)
account.name.update 628.32
account.prefs.update 538.7
tablesdb.rows.increment 408.42
tokens.files.create 406.53
storage.buckets.create 406.11

@loks0n
loks0n marked this pull request as ready for review October 21, 2026 09:56
@luxor-code-review

luxor-code-review Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 S3 getFileInfo returns '' instead of null for missing mime (S3.php:870) — S3::getFileInfo coerces a missing content-type header to an empty string (packages/storage/src/Device/S3.php:870), while FileInfo::$mimeType is declared ?string $mimeType = null to express absence.

The change replaces scattered per-device metadata lookups (size, mime type, hash/etag) with one getFileInfo() returning a FileInfo value object, whose mimeType is nullable so callers can fall back to getFileMimeType().

Files Change
packages/storage/src/FileInfo.php New DTO with optional mimeType (?string, default null) carrying size/hash/metadata from devices.
packages/storage/src/Device/Local.php getFileInfo() probes the local file once for size, MIME type, and metadata instead of three separate reads.
packages/storage/src/Device/S3.php getFileInfo() issues a single HEAD request and derives size, ETag, and content type from response headers.
src/.../Buckets/Files/Create.php Upload finalize path now reads FileInfo once, falling back to getFileMimeType() when mimeType is null.
packages/storage/tests/Device/*.php Unit tests updated for the new getFileInfo() contract on both devices.

One low-severity issue remains: S3 coerces a missing content-type header to an empty string rather than null, which defeats the ?? fallback and skips ambiguous-format resolution; the fix is to pass null and strip ; parameters in S3::getFileInfo().

Reviewed commit: 48173b7

@ghost

ghost commented Oct 21, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental normalization preserves the base MIME type while making absent metadata safely optional, with focused regression coverage.

The pull request adds MIME type to storage FileInfo snapshots and reuses those snapshots while finalizing native uploads, with a refreshed snapshot after metadata stripping and known transformed-byte lengths for stored sizes. Local and S3 devices now provide the metadata, and storage tests cover the device-level MIME behavior. The latest changes normalize optional S3 Content-Type values by removing parameters and representing missing or empty values as null.

Latest changes: The newest commit normalizes S3 Content-Type metadata by trimming whitespace, removing parameters, returning null for missing or empty values, and adding coverage for those cases.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
packages/storage/src/Device/Local.php Includes detected MIME type in Local device file metadata.
packages/storage/src/Device/S3.php Includes normalized optional MIME type in S3 file metadata.
packages/storage/src/FileInfo.php Adds an optional MIME type property to file metadata snapshots.
packages/storage/tests/Device/LocalTest.php Covers MIME type in Local device file metadata.
packages/storage/tests/Device/S3Test.php Covers S3 MIME metadata and normalization of optional Content-Type values.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php Reuses file metadata during upload finalization and uses transformed data length for stored size.

Reviewed the commits since 48173b7 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost 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.

🟢 Tier S · Looks good to merge. Summary

@loks0n
loks0n merged commit 831b229 into main Oct 21, 2026
66 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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