mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-23 23:43:54 +00:00
Add logging for parser cache misses.
This should help us decide whether it would be OK to rely on the ParserCache to store parsed TemplateData. This patch should be reverted once we have collected the desired data. Bug: T266200 Change-Id: I0631806145d46e4a5e7c177797b8fdfe7a152076
This commit is contained in:
parent
aa9f53d0e4
commit
9a85a1b67e
|
@ -1,4 +1,8 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Hooks for TemplateData extension
|
||||
*
|
||||
|
@ -160,6 +164,8 @@ class TemplateDataHooks {
|
|||
public static function onParserFetchTemplateData( array $tplTitles, array &$tplData ): void {
|
||||
$tplData = [];
|
||||
|
||||
self::logBatchUsage( $tplTitles, 'hook' );
|
||||
|
||||
// This inefficient implementation is currently tuned for
|
||||
// Parsoid's use case where it requests info for exactly one title.
|
||||
// For a real batch use case, this code will need an overhaul.
|
||||
|
@ -201,6 +207,8 @@ class TemplateDataHooks {
|
|||
continue;
|
||||
}
|
||||
|
||||
self::logParserCacheStatus( $title );
|
||||
|
||||
$tdb = TemplateDataBlob::newFromDatabase( wfGetDB( DB_REPLICA ), $props[$pageId] );
|
||||
$status = $tdb->getStatus();
|
||||
if ( !$status->isOK() ) {
|
||||
|
@ -277,4 +285,64 @@ class TemplateDataHooks {
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @unstable temporary addition to determine whether we can rely on the parser cache for
|
||||
* storing the parsed TemplateData, instead of putting the data into the page_props table.
|
||||
*
|
||||
* @todo Remove once we have gathers sufficient data on live usage patterns (T266200).
|
||||
*
|
||||
* @param Title $title
|
||||
*/
|
||||
public static function logParserCacheStatus( Title $title ) {
|
||||
$pageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
|
||||
$parserCache = MediaWikiServices::getInstance()->getParserCache();
|
||||
|
||||
$page = $pageFactory->newFromTitle( $title );
|
||||
$meta = $parserCache->getMetadata( $page );
|
||||
|
||||
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
|
||||
$logger = LoggerFactory::getInstance( 'TemplateData' );
|
||||
|
||||
if ( $meta ) {
|
||||
$stats->updateCount( 'templatedata.parsercache.hit', 1 );
|
||||
$logger->debug( 'Parser cache hit', [
|
||||
'template-title' => $title->getPrefixedDBkey(),
|
||||
] );
|
||||
} else {
|
||||
$stats->updateCount( 'templatedata.parsercache.miss', 1 );
|
||||
|
||||
$logger->info( 'Parser cache miss', [
|
||||
'template-title' => $title->getPrefixedDBkey(),
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @unstable temporary addition to determine whether we can rely on the parser cache for
|
||||
* storing the parsed TemplateData, instead of putting the data into the page_props table.
|
||||
*
|
||||
* @todo Remove once we have gathers sufficient data on live usage patterns (T266200).
|
||||
*
|
||||
* @param Title[]|string[] $titles
|
||||
* @param string $context
|
||||
*/
|
||||
public static function logBatchUsage( $titles, $context ) {
|
||||
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
|
||||
$logger = LoggerFactory::getInstance( 'TemplateData' );
|
||||
$size = count( $titles );
|
||||
|
||||
$stats->updateCount( 'templatedata.query.size.' . $size, 1 );
|
||||
|
||||
if ( $size < 2 ) {
|
||||
$logger->debug( 'Single title query', [
|
||||
'context' => $context,
|
||||
] );
|
||||
} else {
|
||||
$logger->info( 'Batch query', [
|
||||
'title-count' => $size,
|
||||
'context' => $context,
|
||||
] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,8 @@ class ApiTemplateData extends ApiBase {
|
|||
$titles = $pageSet->getGoodTitles(); // page_id => Title object
|
||||
$missingTitles = $pageSet->getMissingTitles(); // page_id => Title object
|
||||
|
||||
TemplateDataHooks::logBatchUsage( $pageSet->getTitles(), 'API' );
|
||||
|
||||
$includeMissingTitles = $this->getParameter( 'includeMissingTitles' );
|
||||
$doNotIgnoreMissingTitles = $this->getParameter( 'doNotIgnoreMissingTitles' );
|
||||
if ( $doNotIgnoreMissingTitles ) {
|
||||
|
@ -106,6 +108,8 @@ class ApiTemplateData extends ApiBase {
|
|||
);
|
||||
|
||||
foreach ( $res as $row ) {
|
||||
TemplateDataHooks::logParserCacheStatus( $titles[$row->pp_page] );
|
||||
|
||||
$rawData = $row->pp_value;
|
||||
$tdb = TemplateDataBlob::newFromDatabase( $db, $rawData );
|
||||
$status = $tdb->getStatus();
|
||||
|
|
Loading…
Reference in a new issue