From 6a68b89a57748637d4c9ae0b3b219a0ca7e4ab11 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 9 Sep 2019 15:50:33 -0700 Subject: [PATCH] Cleanup and document some LCStoreDB fields Change-Id: I1edcfbaa0889a84803a9d66d2bc6962664867650 --- includes/cache/localisation/LCStoreDB.php | 32 ++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/includes/cache/localisation/LCStoreDB.php b/includes/cache/localisation/LCStoreDB.php index 88a70421fa..a79325aa61 100644 --- a/includes/cache/localisation/LCStoreDB.php +++ b/includes/cache/localisation/LCStoreDB.php @@ -27,18 +27,20 @@ use Wikimedia\Rdbms\DBQueryError; * This will work on any MediaWiki installation. */ class LCStoreDB implements LCStore { - /** @var string */ - private $currentLang; - /** @var bool */ - private $writesDone = false; + /** @var string Language code */ + private $code; + /** @var array Server configuration map */ + private $server; + + /** @var array Rows buffered for insertion */ + private $batch = []; + /** @var IDatabase|null */ private $dbw; - /** @var array */ - private $batch = []; - /** @var bool */ + /** @var bool Whether a batch of writes were recently written */ + private $writesDone = false; + /** @var bool Whether the DB is read-only or otherwise unavailable for writes */ private $readOnly = false; - /** @var array Server configuration map */ - private $server; public function __construct( $params ) { $this->server = $params['server'] ?? []; @@ -74,14 +76,14 @@ class LCStoreDB implements LCStore { $dbw = $this->getWriteConnection(); $this->readOnly = $dbw->isReadOnly(); - $this->currentLang = $code; + $this->code = $code; $this->batch = []; } public function finishWrite() { if ( $this->readOnly ) { return; - } elseif ( is_null( $this->currentLang ) ) { + } elseif ( is_null( $this->code ) ) { throw new MWException( __CLASS__ . ': must call startWrite() before finishWrite()' ); } @@ -91,7 +93,7 @@ class LCStoreDB implements LCStore { $dbw = $this->getWriteConnection(); $dbw->startAtomic( __METHOD__ ); try { - $dbw->delete( 'l10n_cache', [ 'lc_lang' => $this->currentLang ], __METHOD__ ); + $dbw->delete( 'l10n_cache', [ 'lc_lang' => $this->code ], __METHOD__ ); foreach ( array_chunk( $this->batch, 500 ) as $rows ) { $dbw->insert( 'l10n_cache', $rows, __METHOD__ ); } @@ -108,21 +110,21 @@ class LCStoreDB implements LCStore { $trxProfiler->setSilenced( $oldSilenced ); } - $this->currentLang = null; + $this->code = null; $this->batch = []; } public function set( $key, $value ) { if ( $this->readOnly ) { return; - } elseif ( is_null( $this->currentLang ) ) { + } elseif ( is_null( $this->code ) ) { throw new MWException( __CLASS__ . ': must call startWrite() before set()' ); } $dbw = $this->getWriteConnection(); $this->batch[] = [ - 'lc_lang' => $this->currentLang, + 'lc_lang' => $this->code, 'lc_key' => $key, 'lc_value' => $dbw->encodeBlob( serialize( $value ) ) ]; -- 2.20.1