Skip to content

perf(storage): add listPrefixes to StorageAdapter for efficient brand enumeration (from PR #51 Copilot review) #52

@arndvs

Description

@arndvs

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.tslistBrandSlugs() function

Acceptance criteria:

  • StorageAdapter interface has listPrefixes method
  • Both adapters implement it
  • listBrandSlugs() uses listPrefixes instead of listFiles
  • Existing tests pass, new tests for listPrefixes added

Feedback loops:

  • pnpm test
  • pnpm typecheck

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions