Repository navigation
feat(storage): add CDN cache purging for files and buckets - #1358
Conversation
Adds `StorageFileApi.purgeCache(path:transformationsOnly:)` and `SupabaseStorageClient.purgeBucketCache(_:transformationsOnly:)`, covering `storage.file_buckets.purge_cache` and `storage.file_buckets.purge_bucket_cache`.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughStorage adds file-level and bucket-level cache purge APIs. Both APIs send DELETE requests to CDN cache endpoints. When Sequence Diagram(s)sequenceDiagram
participant Caller
participant StorageSDK
participant CDNCacheEndpoint
Caller->>StorageSDK: Request file or bucket cache purge
StorageSDK->>CDNCacheEndpoint: DELETE cache endpoint
CDNCacheEndpoint-->>StorageSDK: Success response
StorageSDK-->>Caller: Completion
Priority: ⬇️ Low Change: Feature Merge Risk: ⚪ Minimal · up to The cache purge APIs match the documented endpoints and are covered for bucket, file, query, and encoded-path requests. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
grdsdev
left a comment
There was a problem hiding this comment.
Per the Swift API Design Guidelines (clarity at the point of use / include all words needed to avoid ambiguity), the two new purge methods label their identifying argument inconsistently:
try await supabase.storage.from("avatars").purgeCache(path: "user123.png")
try await supabase.storage.purgeBucketCache("avatars", transformationsOnly: true)purgeCache(path:) labels its string because an unlabeled string could mean anything (path, key, URL). purgeBucketCache(_:) does the same job — identifying the thing whose cache gets purged — but leaves it unlabeled. Read on its own, purgeBucketCache("avatars", ...) doesn't make it clear "avatars" is a bucket id, especially with Cache as the noun immediately preceding the argument slot (a reader could momentarily read it as identifying which cache, not which bucket).
Suggest labeling it to match the file-scoped method, and dropping "Bucket" from the base name since the label now carries that meaning (no collision — different receiving types):
public func purgeCache(bucket: String, transformationsOnly: Bool = false) async throwsstorage.from("avatars").purgeCache(path: "user123.png")
storage.purgeCache(bucket: "avatars", transformationsOnly: true)Both call sites now read the same way and disambiguate their argument the same way.
Captures the naming/clarity rules from swift.org's API Design Guidelines as a project skill, alongside swift-docc and writing-migration-guides. Used to review #1358 and drive this PR.
Coverage Report for CI Build 35249473153Coverage increased (+0.02%) to 89.429%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
…delines (#1368) * refactor(storage)!: align remaining API with the Swift API Design Guidelines SortBy.order stored the raw "asc"/"desc" string even though its own initializer already took a type-safe SortOrder, discarding that safety one property read later. Type it SortOrder directly. upload, update, and uploadToSignedURL left their file path unlabeled while every other StorageFileApi method taking a path (download, info, exists, createSignedURL, ...) labels it path:. Label it there too, for the same reason the others do: an unlabeled String at the call site doesn't tell a reader whether it's a path, a key, or a URL. See V3_MIGRATION.md for call-site examples. * chore: add swift-api-design-guidelines skill Captures the naming/clarity rules from swift.org's API Design Guidelines as a project skill, alongside swift-docc and writing-migration-guides. Used to review #1358 and drive this PR.
Adds
purgeCache(path:transformationsOnly:)on a bucket's file API andpurgeCache(bucket:transformationsOnly:)on the Storage client, over Storage'sDELETE /cdn/{bucket}/{path}andDELETE /cdn/{bucket}endpoints. After replacing a file at the same path, a backend can drop the stale CDN copy instead of waiting outcacheControlor adding a cache-busting parameter to every URL.Marks
storage.file_buckets.purge_cacheandstorage.file_buckets.purge_bucket_cacheimplemented insdk-compliance.yaml. The JS and Flutter clients already ship both.Shape
emptyBucketanddeleteBucket. Storage answers{"message":"success"}, which carries nothing a caller can act on.transformationsOnly:becomes?transformations=true, sent only whentrue. JS and Flutter name ittransformations, buttransformations: truereads as "purge the variants too", when it actually purges only the variants and leaves the original cached._getFinalPathandappendingPathComponentasinfoandexists, so a leading/is stripped and the key is percent-encoded. The JS client first shipped this without encoding and fixed it afterwards (fix(storage): url-encode object key in CDN purge methods supabase-js#2545);purgeCachePercentEncodesThePathpins it here.Worth knowing
CDN_PURGE_ENDPOINT_URL, plus thepurgeCachetenant feature on multi-tenant deployments). The doc comments say so.transformationsflag arrived in Storage v1.61.0 (feat: add ability to purge cdn for whole buckets, tenant, and transformations storage#1133). On an older self-hosted Storage,purgeCache(bucket:)gets a route-not-found 404, andpurgeCache(path:transformationsOnly: true)purges the whole file, because the older file route ignores the query.Testing
Five request-snapshot tests: a file, a file with
transformationsOnly, a file path that needs percent-encoding, a bucket, and a bucket withtransformationsOnly. Dropping the query item makes bothtransformationsOnlytests fail.I also ran all four calls through the SDK with a throwaway test (not part of this PR) against Storage v1.77.4 on the local stack, with
CDN_PURGE_ENDPOINT_URLpointed at a stub that logs what Storage forwards. That run predates the rename topurgeCache(bucket:), which only changes the call site: the request snapshots are the same.The two file calls passed
folder/my file.pngand/folder/my file.png, and both reached the purge endpoint as the same object name. The bucket call with the anon key threwStorageErrorwith kind.server, status 403 andAccess denied: Invalid role.The capability matrix checks from
validate-sdk-compliance-swift.yml(pinnedcapability-matrix-v1.6.0) pass locally againstmain, with symbol graphs dumped and normalized the way CI does it.Review first
The
transformationsOnly:label, which departs from the JS and Flutter spelling on purpose.