The Kobo store proxy feature was failing with 404 errors for certain
store endpoints (e.g., /v1/products/featuredforkoboplus/) because
Flask's routing couldn't match these paths. This prevented the Discover
tab from working when "Proxy unknown requests to Kobo Store" was enabled.
Added catch-all routes using Flask's path converter to match any
/v1/products/* paths not handled by more specific routes, allowing
the proxy logic to properly redirect these requests to the official
Kobo store API.
- Add FTS5 table existence check to avoid log spam on non-FTS databases
- Escape FTS5 special characters (quotes) to prevent query errors
- Wrap FTS5 search terms in quotes for phrase matching accuracy
- Improve logging: change author ordering debug to warning for visibility
- Add comment explaining author_sort data issues
These changes improve robustness and security without affecting performance.
This commit introduces several performance optimizations to the search
system, significantly reducing query times for large Calibre libraries.
Key improvements:
1. FTS5 Integration
- Added FTS5 full-text search support with automatic fallback
- Uses indexed search when available, providing sub-second results
- Gracefully degrades to traditional search if FTS5 is unavailable
2. Query Optimization
- Replaced expensive .any() subqueries with efficient JOIN-based
subqueries for tags, series, authors, and publishers
- Reduced SQL complexity and improved query planning
- Added selectinload() for authors to prevent N+1 query problems
3. LIMIT+1 Pattern
- Implemented LIMIT+1 estimation pattern in get_search_results()
- Avoids expensive COUNT(*) operations on large result sets
- Provides fast pagination without sacrificing accuracy
4. Author Ordering Optimization
- Replaced nested database queries with O(1) dictionary lookups
- Eliminated N+1 query anti-pattern in order_authors()
- Reduced author sorting from O(n²) to O(n) complexity
Performance Impact:
In testing with a library of 129,000+ books, these optimizations reduced
search times from 3-9 seconds to 85-330ms, achieving 89-97% improvement
across different search types.
The changes maintain backward compatibility and include fallbacks for
environments without FTS5 support.