From 9d18093909fb29b871f14237f42ecf2a65174518 Mon Sep 17 00:00:00 2001 From: addshore Date: Fri, 1 Apr 2016 15:03:52 +0300 Subject: [PATCH] Track the use of the WatchedItemStore Cache Change-Id: Idc33dd6a52471e895b312fa2c6562a90bf3d7861 --- includes/WatchedItemStore.php | 20 +++++++++++++++++-- .../includes/WatchedItemStoreUnitTest.php | 4 +++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index c4340ad5e1..4f3d640339 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -1,5 +1,6 @@ loadBalancer = $loadBalancer; $this->cache = $cache; + $this->stats = $stats; $this->deferredUpdatesAddCallableUpdateCallback = [ 'DeferredUpdates', 'addCallableUpdate' ]; $this->revisionGetTimestampFromIdCallback = [ 'Revision', 'getTimestampFromId' ]; } @@ -146,7 +155,8 @@ class WatchedItemStore { if ( !self::$instance ) { self::$instance = new self( wfGetLB(), - new HashBagOStuff( [ 'maxKeys' => 100 ] ) + new HashBagOStuff( [ 'maxKeys' => 100 ] ), + RequestContext::getMain()->getStats() ); } return self::$instance; @@ -166,18 +176,22 @@ class WatchedItemStore { $key = $this->getCacheKey( $user, $target ); $this->cache->set( $key, $item ); $this->cacheIndex[$target->getNamespace()][$target->getDBkey()][$user->getId()] = $key; + $this->stats->increment( 'WatchedItemStore.cache' ); } private function uncache( User $user, LinkTarget $target ) { $this->cache->delete( $this->getCacheKey( $user, $target ) ); unset( $this->cacheIndex[$target->getNamespace()][$target->getDBkey()][$user->getId()] ); + $this->stats->increment( 'WatchedItemStore.uncache' ); } private function uncacheLinkTarget( LinkTarget $target ) { if ( !isset( $this->cacheIndex[$target->getNamespace()][$target->getDBkey()] ) ) { return; } + $this->stats->increment( 'WatchedItemStore.uncacheLinkTarget' ); foreach ( $this->cacheIndex[$target->getNamespace()][$target->getDBkey()] as $key ) { + $this->stats->increment( 'WatchedItemStore.uncacheLinkTarget.items' ); $this->cache->delete( $key ); } } @@ -451,8 +465,10 @@ class WatchedItemStore { $cached = $this->getCached( $user, $target ); if ( $cached ) { + $this->stats->increment( 'WatchedItemStore.getWatchedItem.cached' ); return $cached; } + $this->stats->increment( 'WatchedItemStore.getWatchedItem.load' ); return $this->loadWatchedItem( $user, $target ); } diff --git a/tests/phpunit/includes/WatchedItemStoreUnitTest.php b/tests/phpunit/includes/WatchedItemStoreUnitTest.php index 414f3b6643..bc846d33d3 100644 --- a/tests/phpunit/includes/WatchedItemStoreUnitTest.php +++ b/tests/phpunit/includes/WatchedItemStoreUnitTest.php @@ -1,4 +1,5 @@ getMock( StatsdDataFactory::class ) ); } -- 2.20.1