Repository navigation
Don't cache the templates that call one using the current word - #2848
Conversation
93eb083 to
c72c4c9
Compare
|
Good catch! About speed, there is not much we can do. I thought about altering all templates & modules before checking for their cacheable state in order to remove all category handling (since we never use them and we remove them later in the process anyway). But, looking at https://ru.wiktionary.org/w/index.php?title=%D0%A8%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD:%D1%82%D0%B5%D1%80%D0%BC%D0%B8%D0%BD&action=edit it won't be an easy task, and I am afraid we might introduce errors. I always wanted to get rid of categories at the root, maybe do you have a better idea? |
A template that only calls an uncacheable template was cached, and so
was a call written with its namespace (`{{Template:foo}}`). The first
word rendered then decided the output for all the others: in RU the
synonyms of "Украина" lost the word of whichever page came first.
Follow the template calls and redirects at any depth, and compare the
template names without the namespace.
A module requiring an uncacheable module, or expanding an uncacheable
template, is now uncacheable as well, and so are the templates invoking it.
A direct `{{#invoke:...}}` of an uncacheable module is not cached either.
Since `#invoke` calls are part of the graph now, the temporary table of
excluded modules is no longer needed.
c72c4c9 to
a2d9ee2
Compare
When looking for templates & modules using the current word, skip:
- the docs of a template: comments, `<noinclude>`, and what is outside
`<onlyinclude>`, as they are not transcluded
- category links, as they are dropped from the output anyway, while their
sort key is often `{{PAGENAME}}`
- `mw.title.getCurrentTitle().nsText` and `.namespace` in modules, as
words are always in the main namespace
In RU, the uncacheable templates go from 36k to 12k out of 45k.
|
Thanks for merging! About the categories, I went with a lighter version of your idea in d109737: the templates themselves stay untouched, only the cacheable check ignores what never reaches the output. That means category links (even with I did a full RU build of While comparing, I noticed the last commit of #2847 (the trailing newline after a formula) arrived after the merge, so it's in #2849 now. |
Two builds of the same RU dump gave different synonyms for a dozen words. On "Малороссия", "Уркаина", "Незалежная" and the like, the list from
{{шаблон:синонимы:Украина}}dropped a different word each time: whichever page that worker rendered first. So "Уркаина" listed itself, and "Малороссия" lost "Украина" and got "син.: ;" instead.That template only contains
{{синонимы|...}}calls.синонимыredirects toссылки с пометой, which hides the current word (hide={{PAGENAME}}) and is uncacheable. Two gaps let the caller be cached anyway:set_cache_exclusions()only looks at a template's own body (PAGENAME,#invokeof an excluded module) and at direct redirects, so a template that calls an uncacheable template stays cacheableexpand()checkswikitext.startswith("{{" + name), so a call written with the namespace ({{шаблон:...}},{{Template:...}}) never matches an exclusionThe fix:
expand()looks up the name of the called template in itThe catch is speed. In RU the uncacheable templates go from 4084 to 30901 out of 44976, because widely used ones like
термин(and soхим.,истор....) readPAGENAME, if only for a category sort key. On my machine with 12 workers,--renderwent from 11:00 to 17:01. In exchange the output no longer depends on the order the words are rendered in: of the 4.3M entries 79 change (14 distinct articles), all of them now correct.Testing
python:3.13-slimwith the requirements of this branch, RU dump 2026-11-01синонимы:Украина,синонимыandссылки с пометойare uncacheable, no render errors, and the StarDict output differs from the previous build only on those 79 entriesruff format --check,ruff checkandmypypass