2020-09-25 20:02:03 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Cache Parser
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\Parser;
|
|
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
use MediaWiki\Config\ServiceOptions;
|
2020-09-25 20:02:03 +00:00
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
2020-11-18 00:26:53 +00:00
|
|
|
use MediaWiki\Json\JsonCodec;
|
2022-04-26 15:48:03 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2021-03-24 14:05:44 +00:00
|
|
|
use MediaWiki\Page\WikiPageFactory;
|
2022-11-26 01:15:16 +00:00
|
|
|
use MediaWiki\Title\TitleFactory;
|
2020-09-25 20:02:03 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2024-07-09 13:37:44 +00:00
|
|
|
use Wikimedia\ObjectCache\BagOStuff;
|
2024-09-27 18:13:02 +00:00
|
|
|
use Wikimedia\ObjectCache\WANObjectCache;
|
2024-03-04 21:54:52 +00:00
|
|
|
use Wikimedia\Stats\StatsFactory;
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
use Wikimedia\UUID\GlobalIdGenerator;
|
2020-09-25 20:02:03 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns an instance of the ParserCache by its name.
|
|
|
|
|
* @since 1.36
|
|
|
|
|
* @package MediaWiki\Parser
|
|
|
|
|
*/
|
|
|
|
|
class ParserCacheFactory {
|
|
|
|
|
|
|
|
|
|
/** @var string name of ParserCache for the default parser */
|
|
|
|
|
public const DEFAULT_NAME = 'pcache';
|
|
|
|
|
|
2023-03-23 14:48:49 +00:00
|
|
|
/** @var string name of RevisionOutputCache for the default parser */
|
|
|
|
|
public const DEFAULT_RCACHE_NAME = 'rcache';
|
|
|
|
|
|
2020-09-25 20:02:03 +00:00
|
|
|
/** @var BagOStuff */
|
2020-12-04 15:28:25 +00:00
|
|
|
private $parserCacheBackend;
|
2020-09-25 20:02:03 +00:00
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
/** @var WANObjectCache */
|
|
|
|
|
private $revisionOutputCacheBackend;
|
2020-09-25 20:02:03 +00:00
|
|
|
|
|
|
|
|
/** @var HookContainer */
|
|
|
|
|
private $hookContainer;
|
|
|
|
|
|
2020-11-18 00:26:53 +00:00
|
|
|
/** @var JsonCodec */
|
|
|
|
|
private $jsonCodec;
|
2020-10-23 00:17:31 +00:00
|
|
|
|
2024-03-15 11:18:10 +00:00
|
|
|
/** @var StatsFactory */
|
2020-09-25 20:02:03 +00:00
|
|
|
private $stats;
|
|
|
|
|
|
|
|
|
|
/** @var LoggerInterface */
|
|
|
|
|
private $logger;
|
|
|
|
|
|
2021-03-24 14:05:44 +00:00
|
|
|
/** @var TitleFactory */
|
|
|
|
|
private $titleFactory;
|
|
|
|
|
|
|
|
|
|
/** @var WikiPageFactory */
|
|
|
|
|
private $wikiPageFactory;
|
|
|
|
|
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
private GlobalIdGenerator $globalIdGenerator;
|
|
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
/** @var ParserCache[] */
|
|
|
|
|
private $parserCaches = [];
|
|
|
|
|
|
|
|
|
|
/** @var RevisionOutputCache[] */
|
|
|
|
|
private $revisionOutputCaches = [];
|
|
|
|
|
|
|
|
|
|
/** @var ServiceOptions */
|
|
|
|
|
private $options;
|
2020-09-25 20:02:03 +00:00
|
|
|
|
2020-10-12 10:03:18 +00:00
|
|
|
/**
|
2020-12-04 15:28:25 +00:00
|
|
|
* @internal
|
2020-10-12 10:03:18 +00:00
|
|
|
*/
|
2020-12-04 15:28:25 +00:00
|
|
|
public const CONSTRUCTOR_OPTIONS = [
|
2022-04-26 15:48:03 +00:00
|
|
|
MainConfigNames::CacheEpoch,
|
2023-09-28 15:03:33 +00:00
|
|
|
MainConfigNames::ParserCacheFilterConfig,
|
2022-04-26 15:48:03 +00:00
|
|
|
MainConfigNames::OldRevisionParserCacheExpireTime,
|
2020-12-04 15:28:25 +00:00
|
|
|
];
|
2020-10-12 10:03:18 +00:00
|
|
|
|
2020-09-25 20:02:03 +00:00
|
|
|
/**
|
2020-12-04 15:28:25 +00:00
|
|
|
* @param BagOStuff $parserCacheBackend
|
|
|
|
|
* @param WANObjectCache $revisionOutputCacheBackend
|
2020-09-25 20:02:03 +00:00
|
|
|
* @param HookContainer $hookContainer
|
2020-11-18 00:26:53 +00:00
|
|
|
* @param JsonCodec $jsonCodec
|
2024-03-15 11:18:10 +00:00
|
|
|
* @param StatsFactory $stats
|
2020-09-25 20:02:03 +00:00
|
|
|
* @param LoggerInterface $logger
|
2020-12-04 15:28:25 +00:00
|
|
|
* @param ServiceOptions $options
|
2021-03-24 14:05:44 +00:00
|
|
|
* @param TitleFactory $titleFactory
|
|
|
|
|
* @param WikiPageFactory $wikiPageFactory
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
* @param GlobalIdGenerator $globalIdGenerator
|
2020-09-25 20:02:03 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct(
|
2020-12-04 15:28:25 +00:00
|
|
|
BagOStuff $parserCacheBackend,
|
|
|
|
|
WANObjectCache $revisionOutputCacheBackend,
|
2020-09-25 20:02:03 +00:00
|
|
|
HookContainer $hookContainer,
|
2020-11-18 00:26:53 +00:00
|
|
|
JsonCodec $jsonCodec,
|
2024-03-15 11:18:10 +00:00
|
|
|
StatsFactory $stats,
|
2020-10-12 10:03:18 +00:00
|
|
|
LoggerInterface $logger,
|
2021-03-24 14:05:44 +00:00
|
|
|
ServiceOptions $options,
|
|
|
|
|
TitleFactory $titleFactory,
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
WikiPageFactory $wikiPageFactory,
|
|
|
|
|
GlobalIdGenerator $globalIdGenerator
|
2020-09-25 20:02:03 +00:00
|
|
|
) {
|
2020-12-04 15:28:25 +00:00
|
|
|
$this->parserCacheBackend = $parserCacheBackend;
|
|
|
|
|
$this->revisionOutputCacheBackend = $revisionOutputCacheBackend;
|
2020-09-25 20:02:03 +00:00
|
|
|
$this->hookContainer = $hookContainer;
|
2020-11-18 00:26:53 +00:00
|
|
|
$this->jsonCodec = $jsonCodec;
|
2020-09-25 20:02:03 +00:00
|
|
|
$this->stats = $stats;
|
|
|
|
|
$this->logger = $logger;
|
2020-12-04 15:28:25 +00:00
|
|
|
|
|
|
|
|
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
|
|
|
|
|
$this->options = $options;
|
2021-03-24 14:05:44 +00:00
|
|
|
$this->titleFactory = $titleFactory;
|
|
|
|
|
$this->wikiPageFactory = $wikiPageFactory;
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
$this->globalIdGenerator = $globalIdGenerator;
|
2020-09-25 20:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
/**
|
|
|
|
|
* Get a ParserCache instance by $name.
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return ParserCache
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
public function getParserCache( string $name ): ParserCache {
|
2020-12-04 15:28:25 +00:00
|
|
|
if ( !isset( $this->parserCaches[$name] ) ) {
|
2020-09-25 20:02:03 +00:00
|
|
|
$this->logger->debug( "Creating ParserCache instance for {$name}" );
|
2020-10-12 10:03:18 +00:00
|
|
|
$cache = new ParserCache(
|
2020-09-25 21:54:56 +00:00
|
|
|
$name,
|
2020-12-04 15:28:25 +00:00
|
|
|
$this->parserCacheBackend,
|
2022-04-26 15:48:03 +00:00
|
|
|
$this->options->get( MainConfigNames::CacheEpoch ),
|
2020-09-25 20:02:03 +00:00
|
|
|
$this->hookContainer,
|
2020-11-18 00:26:53 +00:00
|
|
|
$this->jsonCodec,
|
2020-09-25 20:02:03 +00:00
|
|
|
$this->stats,
|
2020-10-12 10:03:18 +00:00
|
|
|
$this->logger,
|
2021-03-24 14:05:44 +00:00
|
|
|
$this->titleFactory,
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
$this->wikiPageFactory,
|
|
|
|
|
$this->globalIdGenerator
|
2020-12-04 15:28:25 +00:00
|
|
|
);
|
|
|
|
|
|
2023-09-28 15:03:33 +00:00
|
|
|
$filterConfig = $this->options->get( MainConfigNames::ParserCacheFilterConfig );
|
|
|
|
|
|
|
|
|
|
if ( isset( $filterConfig[$name] ) ) {
|
|
|
|
|
$filter = new ParserCacheFilter( $filterConfig[$name] );
|
|
|
|
|
$cache->setFilter( $filter );
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
$this->parserCaches[$name] = $cache;
|
|
|
|
|
}
|
|
|
|
|
return $this->parserCaches[$name];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a RevisionOutputCache instance by $name.
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return RevisionOutputCache
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
public function getRevisionOutputCache( string $name ): RevisionOutputCache {
|
2020-12-04 15:28:25 +00:00
|
|
|
if ( !isset( $this->revisionOutputCaches[$name] ) ) {
|
|
|
|
|
$this->logger->debug( "Creating RevisionOutputCache instance for {$name}" );
|
|
|
|
|
$cache = new RevisionOutputCache(
|
|
|
|
|
$name,
|
|
|
|
|
$this->revisionOutputCacheBackend,
|
2022-04-26 15:48:03 +00:00
|
|
|
$this->options->get( MainConfigNames::OldRevisionParserCacheExpireTime ),
|
|
|
|
|
$this->options->get( MainConfigNames::CacheEpoch ),
|
2020-12-04 15:28:25 +00:00
|
|
|
$this->jsonCodec,
|
|
|
|
|
$this->stats,
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
$this->logger,
|
|
|
|
|
$this->globalIdGenerator
|
2020-09-25 20:02:03 +00:00
|
|
|
);
|
2020-10-12 10:03:18 +00:00
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
$this->revisionOutputCaches[$name] = $cache;
|
2020-09-25 20:02:03 +00:00
|
|
|
}
|
2020-12-04 15:28:25 +00:00
|
|
|
return $this->revisionOutputCaches[$name];
|
2020-09-25 20:02:03 +00:00
|
|
|
}
|
|
|
|
|
}
|