21use Psr\Log\LoggerInterface;
31 private readonly
MapCacheLRU $previousParseStackTraces;
33 public function __construct(
private readonly LoggerInterface $logger ) {
34 $this->previousParseStackTraces =
new MapCacheLRU( 10 );
47 $pageKey = CacheKeyHelper::getKeyForPage( $page );
51 Title::newFromPageReference( $page )
56 $contentSha1 = $contentStr ? sha1( $contentStr ) :
'INVALID';
58 $index = $this->getParseId( $pageKey, $revId, $optionsHash, $contentSha1 );
60 $stackTrace = (
new RuntimeException() )->getTraceAsString();
61 if ( $this->previousParseStackTraces->has( $index ) ) {
67 __METHOD__ .
': Possibly redundant parse!',
71 'options-hash' => $optionsHash,
72 'contentSha1' => $contentSha1,
73 'trace' => $stackTrace,
74 'previous-trace' => $this->previousParseStackTraces->get( $index ),
78 $this->previousParseStackTraces->set( $index, $stackTrace );
88 private function getParseId(
string $titleStr, ?
int $revId,
string $optionsHash,
string $contentSha1 ): string {
90 $revIdStr = $revId ??
"";
92 return "$titleStr.$revIdStr.$optionsHash.$contentSha1";
Helper class for mapping page value objects to a string key.
Content objects represent page content, e.g.
serialize( $format=null)
Serialize this Content object.
isValid()
Whether the content is valid.