Skip to content

Commit

Permalink
RevisionOutputCache: split metricSuffix into discrete components
Browse files Browse the repository at this point in the history
Breaks up current usage of $metricSuffix into discrete components in
preparation for conversion to StatsLib.

Bug: T356815
Change-Id: I90517e0d5a1dc3f735a5b093529d7797be5ac063
  • Loading branch information
shdubsh committed Mar 7, 2024
1 parent 3e5ec5e commit 081a5ca
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions includes/parser/RevisionOutputCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ public function __construct(
}

/**
* @param string $metricSuffix
* @param string $status e.g. hit, miss etc.
* @param string|null $reason
*/
private function incrementStats( string $metricSuffix ) {
$metricSuffix = str_replace( '.', '_', $metricSuffix );
private function incrementStats( string $status, string $reason = null ) {
$metricSuffix = $reason ? "{$status}_{$reason}" : $status;
$this->stats->increment( "RevisionOutputCache.{$this->name}.{$metricSuffix}" );
}

Expand Down Expand Up @@ -193,21 +194,21 @@ public function get( RevisionRecord $revision, ParserOptions $parserOptions ) {
}

if ( !$parserOptions->isSafeToCache() ) {
$this->incrementStats( 'miss.unsafe' );
$this->incrementStats( 'miss', 'unsafe' );
return false;
}

$cacheKey = $this->makeParserOutputKey( $revision, $parserOptions );
$json = $this->cache->get( $cacheKey );

if ( $json === false ) {
$this->incrementStats( 'miss.absent' );
$this->incrementStats( 'miss', 'absent' );
return false;
}

$output = $this->restoreFromJson( $json, $cacheKey, ParserOutput::class );
if ( $output === null ) {
$this->incrementStats( 'miss.unserialize' );
$this->incrementStats( 'miss', 'unserialize' );
return false;
}

Expand All @@ -216,7 +217,7 @@ public function get( RevisionRecord $revision, ParserOptions $parserOptions ) {
$expiryTime = max( $expiryTime, (int)MWTimestamp::now( TS_UNIX ) - $this->cacheExpiry );

if ( $cacheTime < $expiryTime ) {
$this->incrementStats( 'miss.expired' );
$this->incrementStats( 'miss', 'expired' );
return false;
}

Expand Down Expand Up @@ -278,23 +279,23 @@ public function save(

$expiry = $output->getCacheExpiry();
if ( $expiry <= 0 ) {
$this->incrementStats( 'save.uncacheable' );
$this->incrementStats( 'save', 'uncacheable' );
return;
}

if ( !$parserOptions->isSafeToCache() ) {
$this->incrementStats( 'save.unsafe' );
$this->incrementStats( 'save', 'unsafe' );
return;
}

$json = $this->encodeAsJson( $output, $cacheKey );
if ( $json === null ) {
$this->incrementStats( 'save.nonserializable' );
$this->incrementStats( 'save', 'nonserializable' );
return;
}

$this->cache->set( $cacheKey, $json, $expiry );
$this->incrementStats( 'save.success' );
$this->incrementStats( 'save', 'success' );
}

/**
Expand Down

0 comments on commit 081a5ca

Please sign in to comment.