discourse/plugins/discourse-ai/app
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
..
controllers PERF: Optimize AI translation stats query and remove caching (#35597) 2025-10-27 14:03:21 -03:00
helpers/discourse_ai/ai_bot
jobs DEV: Add more early exits for credit limits on translation jobs (#35578) 2025-10-23 13:04:18 -07:00
mailers
models DEV: AI credits should reset at start of month (#35587) 2025-10-24 06:30:32 -07:00
serializers FEATURE: Hosted LLM credit system (#35162) 2025-10-14 07:48:20 -07:00
services FIX: Don’t create AI Problem check trackers without a target LLM. (#35447) 2025-10-16 12:38:06 -03:00
views