discourse/plugins/discourse-ai/spec/system
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
..
ai_bot UX: Move AI bot PM to navigation menu (#35189) 2025-10-20 09:15:51 -04:00
ai_helper DEV: Update rubocop-discourse to 3.13 and autofix issues (#35073) 2025-10-06 16:11:01 +02:00
ai_moderation DEV: Add client settled checks for system tests (#35230) 2025-10-10 11:03:18 +08:00
embeddings DEV: Update rubocop-discourse to 3.13 and autofix issues (#35073) 2025-10-06 16:11:01 +02:00
llms DEV: Update rubocop-discourse to 3.13 and autofix issues (#35073) 2025-10-06 16:11:01 +02:00
page_objects FIX: AI usage doesn't refresh custom date ranges correctly (#34816) 2025-09-16 10:16:01 -07:00
summarization UX: show AI gist toggle on /filter route, fix appearance of gists (#35521) 2025-10-21 16:08:19 -04:00
admin_ai_features_spec.rb DEV: Update rubocop-discourse to 3.13 and autofix issues (#35073) 2025-10-06 16:11:01 +02:00
admin_ai_persona_spec.rb DEV: Add client settled checks for system tests (#35230) 2025-10-10 11:03:18 +08:00
admin_ai_translations_spec.rb PERF: Optimize AI translation stats query and remove caching (#35597) 2025-10-27 14:03:21 -03:00
admin_dashboard_spec.rb
ai_artifact_key_value_api_spec.rb
ai_usage_spec.rb FIX: AI usage doesn't refresh custom date ranges correctly (#34816) 2025-09-16 10:16:01 -07:00
ai_user_preferences_spec.rb FEATURE: Promote Discover to a dedicated feature. (#34846) 2025-09-23 14:01:45 -03:00
core_features_spec.rb