Problem
Drupal 7 serves the numbers of the "Explore languages" page from a cache it rebuilds hourly on cron (and clears for a language after an import), with one grouped query for the translation and suggestion counts of every language. On 3.0.x the page runs four uncached count queries per language on every render, one of them a full count of the source strings table, and the page is rendered again after every translation saved on the site. With a hundred languages and millions of strings that is a few hundred heavy queries per view.
Proposed resolution
- The page takes every number from the statistics service's cached grouped queries (translations and suggestions per language, contributors per language), with the live string count Drupal 7 also used.
- The statistics service gets a cache tag and a
clearCache(); the page carries the tag and the cache lifetime, so a cleared cache reaches the rendered page and nothing stays older than the lifetime. - An import clears the statistics, like on Drupal 7 (the todo left in the import form).
- The uncached per-language query goes, nothing else used it.
Tests
Drupal 7 first: testLanguageStatisticsCache() primes the page, approves a translation on the site, checks the page still shows the cached numbers, runs cron and checks the rebuilt numbers. Ported as L10nLanguageStatisticsTest, where the cache lifetime ending is the rebuild and an import shows up right away.
LLM disclosure
LLM was used to find, diagnose explain and fix this issue. With human review.
Comments
Comment #4
gábor hojtsy