discourse/plugins/discourse-ai/app/controllers
Rafael dos Santos Silva 3af793eaf2
PERF: Optimize AI translation stats query and remove caching (#35597)
## Summary
Consolidates two separate SQL queries into a single optimized query that
returns translation progress along with aggregate counts. This reduces
database round-trips from 2 to 1 per request.

With the improved query performance, caching is no longer necessary,
simplifying the codebase by removing cache management overhead.

## Changes
- Modified `PostCandidates.completion_all_locales` to return aggregate
counts (total and posts_with_detected_locale) in addition to per-locale
translation progress
- Updated controller to use single query method instead of two separate
calls
- Removed caching infrastructure (CACHE_TTL, cache key methods, cache
clearing logic)
- Updated tests to reflect new return format

## Performance Impact
- **Before**: 2 SQL queries + 2 cache entries + cache invalidation logic
- **After**: 1 optimized SQL query + no caching overhead

## Test Plan
All existing tests pass:
- `plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb`
-
`plugins/discourse-ai/spec/requests/admin/ai_translations_controller_spec.rb`
2025-10-27 14:03:21 -03:00
..
concerns FEATURE: Hosted LLM credit system (#35162) 2025-10-14 07:48:20 -07:00
discourse_ai PERF: Optimize AI translation stats query and remove caching (#35597) 2025-10-27 14:03:21 -03:00