From: Aaron Schulz Date: Wed, 11 Jul 2018 13:11:12 +0000 (+0100) Subject: Convert LinkCache to using MapCacheLRU X-Git-Tag: 1.34.0-rc.0~4753 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=b4c8614885a4b21415b81245c69fe89c30858adf;p=lhc%2Fweb%2Fwiklou.git Convert LinkCache to using MapCacheLRU Clean up the variable names while at it. Change-Id: I3b7860c0657111d73567e247bcc1ebcbaef53e22 --- diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index 58ed771a9c..260038af5f 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -32,10 +32,10 @@ use MediaWiki\MediaWikiServices; * @ingroup Cache */ class LinkCache { - /** @var HashBagOStuff */ - private $mGoodLinks; - /** @var HashBagOStuff */ - private $mBadLinks; + /** @var MapCacheLRU */ + private $goodLinks; + /** @var MapCacheLRU */ + private $badLinks; /** @var WANObjectCache */ private $wanCache; @@ -52,8 +52,8 @@ class LinkCache { const MAX_SIZE = 10000; public function __construct( TitleFormatter $titleFormatter, WANObjectCache $cache ) { - $this->mGoodLinks = new HashBagOStuff( [ 'maxKeys' => self::MAX_SIZE ] ); - $this->mBadLinks = new HashBagOStuff( [ 'maxKeys' => self::MAX_SIZE ] ); + $this->goodLinks = new MapCacheLRU( self::MAX_SIZE ); + $this->badLinks = new MapCacheLRU( self::MAX_SIZE ); $this->wanCache = $cache; $this->titleFormatter = $titleFormatter; } @@ -87,7 +87,7 @@ class LinkCache { * @return int Page ID or zero */ public function getGoodLinkID( $title ) { - $info = $this->mGoodLinks->get( $title ); + $info = $this->goodLinks->get( $title ); if ( !$info ) { return 0; } @@ -103,7 +103,7 @@ class LinkCache { */ public function getGoodLinkFieldObj( LinkTarget $target, $field ) { $dbkey = $this->titleFormatter->getPrefixedDBkey( $target ); - $info = $this->mGoodLinks->get( $dbkey ); + $info = $this->goodLinks->get( $dbkey ); if ( !$info ) { return null; } @@ -116,7 +116,7 @@ class LinkCache { */ public function isBadLink( $title ) { // Use get() to ensure it records as used for LRU. - return $this->mBadLinks->get( $title ) !== false; + return $this->badLinks->has( $title ); } /** @@ -134,7 +134,7 @@ class LinkCache { $revision = 0, $model = null, $lang = null ) { $dbkey = $this->titleFormatter->getPrefixedDBkey( $target ); - $this->mGoodLinks->set( $dbkey, [ + $this->goodLinks->set( $dbkey, [ 'id' => (int)$id, 'length' => (int)$len, 'redirect' => (int)$redir, @@ -153,7 +153,7 @@ class LinkCache { */ public function addGoodLinkObjFromRow( LinkTarget $target, $row ) { $dbkey = $this->titleFormatter->getPrefixedDBkey( $target ); - $this->mGoodLinks->set( $dbkey, [ + $this->goodLinks->set( $dbkey, [ 'id' => intval( $row->page_id ), 'length' => intval( $row->page_len ), 'redirect' => intval( $row->page_is_redirect ), @@ -169,7 +169,7 @@ class LinkCache { public function addBadLinkObj( LinkTarget $target ) { $dbkey = $this->titleFormatter->getPrefixedDBkey( $target ); if ( !$this->isBadLink( $dbkey ) ) { - $this->mBadLinks->set( $dbkey, 1 ); + $this->badLinks->set( $dbkey, 1 ); } } @@ -177,7 +177,7 @@ class LinkCache { * @param string $title Prefixed DB key */ public function clearBadLink( $title ) { - $this->mBadLinks->delete( $title ); + $this->badLinks->clear( $title ); } /** @@ -185,8 +185,8 @@ class LinkCache { */ public function clearLink( LinkTarget $target ) { $dbkey = $this->titleFormatter->getPrefixedDBkey( $target ); - $this->mBadLinks->delete( $dbkey ); - $this->mGoodLinks->delete( $dbkey ); + $this->badLinks->clear( $dbkey ); + $this->goodLinks->clear( $dbkey ); } /** @@ -332,7 +332,7 @@ class LinkCache { * Clears cache */ public function clear() { - $this->mGoodLinks->clear(); - $this->mBadLinks->clear(); + $this->goodLinks->clear(); + $this->badLinks->clear(); } }