-
Notifications
You must be signed in to change notification settings - Fork 0
Product route: Linear search O(n) for by-ID lookups #21
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request