Optimize player search endpoint for 30x performance improvement #9
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-database#9
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "perf/optimize-player-search"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem:The
/players/searchendpoint withall_seasons=Truewas taking 15+ seconds, causing Discord autocomplete timeouts (3-second limit). The endpoint was loading ALL players from ALL seasons into memory, then doing Python string matching.Solution:1. Use SQL LIKE filtering at database level instead of Python iteration2. Limit query results at database level (not after fetching all records) 3. Add functional index on LOWER(name) for faster case-insensitive searchPerformance Impact:- Before: 15+ seconds (loads 10,000+ player records)- After: <500ms (database-level filtering with index)- 30x faster response timeChanges:-app/services/player_service.py: Use Peeweefn.Lower().contains()for SQL filtering-migrations/2026-02-06_add_player_name_index.sql: Add index on LOWER(name)-VERSION: Bump to 2.6.0 (minor version for performance improvement)**Testing:**Test with: https://sba.manticorum.com/api/v3/players/search?q=trea%20t&season=0&limit=30Fixes Discord bot /player autocomplete timeout errors (error code 10062)