[MediaWiki-commits] [Gerrit] Don't trigger MessageBlobStore during tests - change (mediawiki/core)

2015-04-02 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Don't trigger MessageBlobStore during tests
..


Don't trigger MessageBlobStore during tests

The test for OutputPage::makeResourceLoaderLink was triggering database
queries through MessageBlobStore even though it doesn't use any
messages.

In bb03d1a8e08 I had made MessageBlobStore a singleton instead of static
functions, however there's no need for it to be one since the class is
stateless. Callers can just create a new MessageBlobStore instance and
call functions upon it. Using getInstance() is now deprecated.

ResourceLoader now has a setMessageBlobStore setter to allow overriding
which MessageBlobStore instance will be used. OutputPageTest uses this
to set a NullMessageBlobStore, which makes no database queries.

Change-Id: Ica7436fb6f1ea59bd445b02527829ab0742c0842
---
M includes/MessageBlobStore.php
M includes/cache/LocalisationCache.php
M includes/cache/MessageCache.php
M includes/installer/DatabaseUpdater.php
M includes/resourceloader/ResourceLoader.php
M tests/phpunit/includes/OutputPageTest.php
6 files changed, 48 insertions(+), 10 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/MessageBlobStore.php b/includes/MessageBlobStore.php
index c384188..011cae6 100644
--- a/includes/MessageBlobStore.php
+++ b/includes/MessageBlobStore.php
@@ -36,15 +36,12 @@
 * Get the singleton instance
 *
 * @since 1.24
+* @deprecated since 1.25
 * @return MessageBlobStore
 */
public static function getInstance() {
-   static $instance = null;
-   if ( $instance === null ) {
-   $instance = new self;
-   }
-
-   return $instance;
+   wfDeprecated( __METHOD__, '1.25' );
+   return new self;
}
 
/**
diff --git a/includes/cache/LocalisationCache.php 
b/includes/cache/LocalisationCache.php
index e270f5f..dc5a2eb 100644
--- a/includes/cache/LocalisationCache.php
+++ b/includes/cache/LocalisationCache.php
@@ -1020,7 +1020,8 @@
# HACK: If using a null (i.e. disabled) storage backend, we
# can't write to the MessageBlobStore either
if ( $purgeBlobs  !$this-store instanceof LCStoreNull ) {
-   MessageBlobStore::getInstance()-clear();
+   $blobStore = new MessageBlobStore();
+   $blobStore-clear();
}
 
}
diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php
index 04f5887..82919c7 100644
--- a/includes/cache/MessageCache.php
+++ b/includes/cache/MessageCache.php
@@ -562,7 +562,8 @@
 
// Update the message in the message blob store
global $wgContLang;
-   MessageBlobStore::getInstance()-updateMessage( 
$wgContLang-lcfirst( $msg ) );
+   $blobStore = new MessageBlobStore();
+   $blobStore-updateMessage( $wgContLang-lcfirst( $msg ) );
 
Hooks::run( 'MessageCacheReplace', array( $title, $text ) );
 
diff --git a/includes/installer/DatabaseUpdater.php 
b/includes/installer/DatabaseUpdater.php
index b676f45..12ef91a 100644
--- a/includes/installer/DatabaseUpdater.php
+++ b/includes/installer/DatabaseUpdater.php
@@ -932,7 +932,8 @@
if ( $wgLocalisationCacheConf['manualRecache'] ) {
$this-rebuildLocalisationCache();
}
-   MessageBlobStore::getInstance()-clear();
+   $blobStore = new MessageBlobStore();
+   $blobStore-clear();
$this-output( done.\n );
}
 
diff --git a/includes/resourceloader/ResourceLoader.php 
b/includes/resourceloader/ResourceLoader.php
index 5eab3cb..b9d1b2b 100644
--- a/includes/resourceloader/ResourceLoader.php
+++ b/includes/resourceloader/ResourceLoader.php
@@ -73,6 +73,11 @@
protected $errors = array();
 
/**
+* @var MessageBlobStore
+*/
+   protected $blobStore;
+
+   /**
 * Load information stored in the database about modules.
 *
 * This method grabs modules dependencies from the database and updates 
modules
@@ -250,6 +255,7 @@
$this-registerTestModules();
}
 
+   $this-setMessageBlobStore( new MessageBlobStore() );
}
 
/**
@@ -257,6 +263,14 @@
 */
public function getConfig() {
return $this-config;
+   }
+
+   /**
+* @param MessageBlobStore $blobStore
+* @since 1.25
+*/
+   public function setMessageBlobStore( MessageBlobStore $blobStore ) {
+   $this-blobStore = $blobStore;
}
 
/**
@@ -885,7 +899,7 @@
// Pre-fetch blobs
if ( 

[MediaWiki-commits] [Gerrit] Don't trigger MessageBlobStore during tests - change (mediawiki/core)

2015-03-28 Thread Legoktm (Code Review)
Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/200331

Change subject: Don't trigger MessageBlobStore during tests
..

Don't trigger MessageBlobStore during tests

The test for OutputPage::makeResourceLoaderLink was triggering database
queries through MessageBlobStore even though it doesn't use any
messages.

In bb03d1a8e08 I had made MessageBlobStore a singleton instead of static
functions, however there's no need for it to be one since the class is
stateless. Callers can just create a new MessageBlobStore instance and
call functions upon it. Using getInstance() is now deprecated.

ResourceLoader now has a setMessageBlobStore setter to allow overriding
which MessageBlobStore instance will be used. OutputPageTest uses this
to set a NullMessageBlobStore, which makes no database queries.

Change-Id: Ica7436fb6f1ea59bd445b02527829ab0742c0842
---
M includes/MessageBlobStore.php
M includes/cache/LocalisationCache.php
M includes/cache/MessageCache.php
M includes/installer/DatabaseUpdater.php
M includes/resourceloader/ResourceLoader.php
M tests/phpunit/includes/OutputPageTest.php
6 files changed, 48 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/31/200331/1

diff --git a/includes/MessageBlobStore.php b/includes/MessageBlobStore.php
index c384188..011cae6 100644
--- a/includes/MessageBlobStore.php
+++ b/includes/MessageBlobStore.php
@@ -36,15 +36,12 @@
 * Get the singleton instance
 *
 * @since 1.24
+* @deprecated since 1.25
 * @return MessageBlobStore
 */
public static function getInstance() {
-   static $instance = null;
-   if ( $instance === null ) {
-   $instance = new self;
-   }
-
-   return $instance;
+   wfDeprecated( __METHOD__, '1.25' );
+   return new self;
}
 
/**
diff --git a/includes/cache/LocalisationCache.php 
b/includes/cache/LocalisationCache.php
index e270f5f..dc5a2eb 100644
--- a/includes/cache/LocalisationCache.php
+++ b/includes/cache/LocalisationCache.php
@@ -1020,7 +1020,8 @@
# HACK: If using a null (i.e. disabled) storage backend, we
# can't write to the MessageBlobStore either
if ( $purgeBlobs  !$this-store instanceof LCStoreNull ) {
-   MessageBlobStore::getInstance()-clear();
+   $blobStore = new MessageBlobStore();
+   $blobStore-clear();
}
 
}
diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php
index 04f5887..82919c7 100644
--- a/includes/cache/MessageCache.php
+++ b/includes/cache/MessageCache.php
@@ -562,7 +562,8 @@
 
// Update the message in the message blob store
global $wgContLang;
-   MessageBlobStore::getInstance()-updateMessage( 
$wgContLang-lcfirst( $msg ) );
+   $blobStore = new MessageBlobStore();
+   $blobStore-updateMessage( $wgContLang-lcfirst( $msg ) );
 
Hooks::run( 'MessageCacheReplace', array( $title, $text ) );
 
diff --git a/includes/installer/DatabaseUpdater.php 
b/includes/installer/DatabaseUpdater.php
index b676f45..12ef91a 100644
--- a/includes/installer/DatabaseUpdater.php
+++ b/includes/installer/DatabaseUpdater.php
@@ -932,7 +932,8 @@
if ( $wgLocalisationCacheConf['manualRecache'] ) {
$this-rebuildLocalisationCache();
}
-   MessageBlobStore::getInstance()-clear();
+   $blobStore = new MessageBlobStore();
+   $blobStore-clear();
$this-output( done.\n );
}
 
diff --git a/includes/resourceloader/ResourceLoader.php 
b/includes/resourceloader/ResourceLoader.php
index 5eab3cb..b9d1b2b 100644
--- a/includes/resourceloader/ResourceLoader.php
+++ b/includes/resourceloader/ResourceLoader.php
@@ -73,6 +73,11 @@
protected $errors = array();
 
/**
+* @var MessageBlobStore
+*/
+   protected $blobStore;
+
+   /**
 * Load information stored in the database about modules.
 *
 * This method grabs modules dependencies from the database and updates 
modules
@@ -250,6 +255,7 @@
$this-registerTestModules();
}
 
+   $this-setMessageBlobStore( new MessageBlobStore() );
}
 
/**
@@ -257,6 +263,14 @@
 */
public function getConfig() {
return $this-config;
+   }
+
+   /**
+* @param MessageBlobStore $blobStore
+* @since 1.25
+*/
+   public function setMessageBlobStore( MessageBlobStore $blobStore ) {
+   $this-blobStore = $blobStore;
}
 
/**
@@ -885,7 +899,7 @@
// Pre-fetch