Parent PR: #51
Source comment: #51 (comment)
File: lib/cast/server/brand-loader.ts:236
Confidence: 10 = [50 +20 specific −25 vague ("consider extending") −15 cross-module −20 shared util = 10]
Interpretation
listBrandSlugs() calls storage.listFiles("inputs", "brands") which recursively enumerates every file under all brands. On Azure Blob with many brands, this is unnecessarily expensive when we only need to discover brand slug names.
Proposed approach
- Add
listPrefixes(container, prefix, delimiter?) to the StorageAdapter interface
LocalFsAdapter: implement via fs.readdir with withFileTypes: true, return only directory names
AzureBlobAdapter: implement via BlobServiceClient.listBlobsByHierarchy(delimiter) which returns virtual directory prefixes without enumerating all blobs
- Update
listBrandSlugs() to call storage.listPrefixes("inputs", "brands/") instead of storage.listFiles("inputs", "brands")
Blockers / questions
- Current brand count is small (2-3 brands), so this is an optimization for future scale, not a current bottleneck
- Need to decide on return format: just slug strings, or full prefix paths like
brands/acme/
Context
Files to read:
lib/cast/server/storage-adapter.ts — StorageAdapter interface and both adapter implementations
lib/cast/server/brand-loader.ts — listBrandSlugs() function
Acceptance criteria:
Feedback loops:
Parent PR: #51
Source comment: #51 (comment)
File:
lib/cast/server/brand-loader.ts:236Confidence: 10 = [50 +20 specific −25 vague ("consider extending") −15 cross-module −20 shared util = 10]
Interpretation
listBrandSlugs()callsstorage.listFiles("inputs", "brands")which recursively enumerates every file under all brands. On Azure Blob with many brands, this is unnecessarily expensive when we only need to discover brand slug names.Proposed approach
listPrefixes(container, prefix, delimiter?)to theStorageAdapterinterfaceLocalFsAdapter: implement viafs.readdirwithwithFileTypes: true, return only directory namesAzureBlobAdapter: implement viaBlobServiceClient.listBlobsByHierarchy(delimiter)which returns virtual directory prefixes without enumerating all blobslistBrandSlugs()to callstorage.listPrefixes("inputs", "brands/")instead ofstorage.listFiles("inputs", "brands")Blockers / questions
brands/acme/Context
Files to read:
lib/cast/server/storage-adapter.ts— StorageAdapter interface and both adapter implementationslib/cast/server/brand-loader.ts—listBrandSlugs()functionAcceptance criteria:
StorageAdapterinterface haslistPrefixesmethodlistBrandSlugs()useslistPrefixesinstead oflistFileslistPrefixesaddedFeedback loops:
pnpm testpnpm typecheck