perf: Optimize recommendation system and improve error handling

- Fix N+1 query problem in preset package fetching
  * Search with limit 5 to find best matches
  * Case-insensitive package name matching
  * Fallback to most popular when no exact match

- Improve category filtering accuracy
  * Update category mapping to match database schema
  * Remove duplicate packages in category fetching
  * Better distribution across categories

- Add version control for localStorage profile
  * Support future schema migrations
  * Auto-migrate old profiles to new version
  * Persist version in localStorage

- Enhance error handling
  * Specific error messages for 400/500/404 responses
  * Network error detection
  * User-friendly error messages in UI

- Fix OS detection fallback
  * Default to ubuntu when detection returns unknown
  * Prevent empty OS selection in onboarding

- Add better API validation
  * Explicit limit range validation (1-50)
  * Clear error messages for invalid inputs
This commit is contained in:
ersaayan
2025-11-22 17:47:52 +03:00
parent bcf8652728
commit f8fffdce83
6 changed files with 88 additions and 30 deletions
+8 -3
View File
@@ -64,9 +64,14 @@ export async function POST(request: NextRequest) {
);
}
// Set default limit
const limit =
body.limit && body.limit > 0 && body.limit <= 50 ? body.limit : 20;
// Validate and set limit with better error message
if (body.limit !== undefined && (body.limit < 1 || body.limit > 50)) {
return NextResponse.json(
{ error: "Limit must be between 1 and 50" },
{ status: 400 }
);
}
const limit = body.limit && body.limit > 0 && body.limit <= 50 ? body.limit : 20;
// Generate recommendations
const recommendations = await RecommendationService.generateRecommendations(