Skip to content

Product route: Linear search O(n) for by-ID lookups #21

@thomasiverson

Description

@thomasiverson

Severity: Low

Category: Performance

Description

In api/src/routes/product.ts, all by-ID lookups use Array.find() / Array.findIndex() which is O(n). Not critical for the current in-memory demo, but a Map<number, Product> would provide O(1) lookups if the dataset grows.

Suggested Fix

Use a Map for product storage indexed by productId:

const productMap = new Map<number, Product>();
seedProducts.forEach(p => productMap.set(p.productId, p));

Affected File

  • api/src/routes/product.ts (GET/:id, PUT/:id, DELETE/:id handlers)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions