Page MenuHomePhabricator

Collapsable sections split the parser cache
Open, Needs TriagePublic


Currently the setCollapsibleSections parser option splits the parser cache, which means that mobile content is stored in the parser cache twice, despite the section collapsing being a post-processing transformation.

As part of T348255's work to refine the ParserCache mechanism, we should introduce a ParserOptions type for "propagated to ParserOutput but not otherwise affecting the parse". These options would be omitted from the ParserCache key, but when a ParserOutput is retrieved based on the modified key is needs to be "fixed up" by propagating the *actual* ParserOptions to the ParserOutput using setFromParserOptions in a way which also overwrites any of that metadata left over from the original parse. (Or the original parse should always have the options wiped, so that the ParserOutput is a clean slate that we can naively run ParserOutput::setFromParserOptions on -- the problematic case is the output class wrapper, since ParserOutput::addWrapperDivClass will *append* a class to the one from the preview parse instead of overwriting it).

For example, a parse with 'wrap output class' set to foo should get parsed and stored as normal, but with wrap output class omitted from the ParserOptions and therefore result in a ParserOutput with an empty wrapper div class set, which is what is stored in the cache. ParserOutput::setFromParserOptions() is then called to transfer the 'foo' class to the ParserOutput before it is returned from ParserOutputAccess.

Then a subsequent parse with wrap output class set to bar would get 'wrap output class' omitted from the cache key and so could return the previously-rendered ParserOutput with an empty wrapper div class. Again, ParserOutput::setFromParserOptions() would be set on the ParserOutput fetched from the cache to transfer the 'bar' class to the ParserOutput before ParserOutputAccess returns.