ParserOutputPostCacheTransform: Don't reprocess content

* getText() could be called multiple times on a ParserCache object
  which would fire the ParserOutputPostCacheTransform handler
  multiple times.

  But, I could not track down how this could happen right now.

* As a separate issue, while conceptually there are no restrictions
  against calling getText() multiple times, there is a semantics and
  performance issue if that did actually happen. getText() does a
  bunch of transformations and makes no effort to avoid duplicate
  work. It will accumulate more transformations over time via the
  OutputTranform pipeline and it is preferable for getText() and/or
  the OutputTransform pipeline to guarantee semantics where the
  pipeline won't be run multiple times on the same content. That will
  free both hook handlers (like this) and the transforms themselves
  to avoid checks as in this patch.

  This patch should be reverted once such a change is made to core.

Bug: T351461
Change-Id: If5dfa0954e3fd2b7dbea1ed29b475be07f0f3986
(cherry picked from commit 7aaaf51dfd)
This commit is contained in:
Subramanya Sastry 2023-11-17 15:20:46 -06:00
parent 3f930983c5
commit 5b2142b9c7

View file

@ -86,6 +86,12 @@ class ParserHooks implements
* @inheritDoc
*/
public function onParserOutputPostCacheTransform( $parserOutput, &$text, &$options ): void {
if ( $parserOutput->getExtensionData( 'DiscussionTools-tocInfo' ) !== null ) {
// Since getText() could be called multiple times, return if we have
// already processed this ParserOutput object
return;
}
// NOTE: This is a temporary proxy for 'isPreview' flag in ParserOptions.
// It is not clear whether 'editsectionEditLinks' is disabled only for previews.
$isPreview = empty( $options['enableSectionEditLinks'] );