jenkins-bot has submitted this change and it was merged.

Change subject: resourceloader: Update MessageBlobStore documentation and code 
cleanup
......................................................................


resourceloader: Update MessageBlobStore documentation and code cleanup

* Update and improve class documentation.

* Remove comment that claims to return false if the module has no message.
  generateMessageBlob() returns '{}' in that case. And this is expected since
  we want to cache the absence of messages.

* Re-use the module objects passed to MessageBlobStore::get() in getFromDB()
  instead of using ResourceLoader::getModule(). The object is the same either
  way (since ResourceLoader re-uses the objects also) but reduces complexity
  of getFromDB() to not need the ResourceLoader object as parameter.

Change-Id: I89a14d7185877fae52791f6837883ed3a6749cd7
---
M includes/cache/MessageBlobStore.php
1 file changed, 13 insertions(+), 15 deletions(-)

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



diff --git a/includes/cache/MessageBlobStore.php 
b/includes/cache/MessageBlobStore.php
index 4f0824f..624bbc9 100644
--- a/includes/cache/MessageBlobStore.php
+++ b/includes/cache/MessageBlobStore.php
@@ -23,13 +23,12 @@
  */
 
 /**
- * This class provides access to the resource message blobs storage used
- * by ResourceLoader.
+ * This class provides access to the message blobs used by ResourceLoader 
modules.
  *
  * A message blob is a JSON object containing the interface messages for a
- * certain resource in a certain language. These message blobs are cached
- * in the msg_resource table and automatically invalidated when one of their
- * constituent messages or the resource itself is changed.
+ * certain module in a certain language. These message blobs are cached
+ * in the automatically invalidated when one of their constituent messages,
+ * or the module definition, is changed.
  */
 class MessageBlobStore {
        /**
@@ -72,13 +71,13 @@
                        if ( isset( $this->blobCache[$lang][$name] ) ) {
                                $blobs[$name] = $this->blobCache[$lang][$name];
                        } else {
-                               $missingFromCache[] = $name;
+                               $missingFromCache[$name] = $module;
                        }
                }
 
                // Try DB cache
                if ( $missingFromCache ) {
-                       $blobs += $this->getFromDB( $resourceLoader, 
$missingFromCache, $lang );
+                       $blobs += $this->getFromDB( $missingFromCache, $lang );
                }
 
                // Generate new blobs for any remaining modules and store in DB
@@ -108,7 +107,7 @@
         * @param string $name Module name
         * @param ResourceLoaderModule $module
         * @param string $lang Language code
-        * @return mixed Message blob or false if the module has no messages
+        * @return string JSON blob
         */
        public function insertMessageBlob( $name, ResourceLoaderModule $module, 
$lang ) {
                $blob = $this->generateMessageBlob( $module, $lang );
@@ -340,13 +339,12 @@
         * Get the message blobs for a set of modules from the database.
         * Modules whose blobs are not in the database are silently dropped.
         *
-        * @param ResourceLoader $resourceLoader
-        * @param array $modules Array of module names
+        * @param array $modules Array of module objects by name
         * @param string $lang Language code
         * @throws MWException
         * @return array Array mapping module names to blobs
         */
-       private function getFromDB( ResourceLoader $resourceLoader, $modules, 
$lang ) {
+       private function getFromDB( $modules, $lang ) {
                if ( !count( $modules ) ) {
                        return array();
                }
@@ -355,16 +353,16 @@
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( 'msg_resource',
                        array( 'mr_blob', 'mr_resource', 'mr_timestamp' ),
-                       array( 'mr_resource' => $modules, 'mr_lang' => $lang ),
+                       array( 'mr_resource' => array_keys( $modules ), 
'mr_lang' => $lang ),
                        __METHOD__
                );
 
                foreach ( $res as $row ) {
-                       $module = $resourceLoader->getModule( $row->mr_resource 
);
-                       if ( !$module ) {
+                       if ( !isset( $modules[ $row->mr_resource ] ) ) {
                                // This shouldn't be possible
                                throw new MWException( __METHOD__ . ' passed an 
invalid module name' );
                        }
+                       $module = $modules[ $row->mr_resource ];
 
                        // Update the module's blob if the list of messages 
changed
                        $blobKeys = array_keys( FormatJson::decode( 
$row->mr_blob, true ) );
@@ -384,7 +382,7 @@
         *
         * @param ResourceLoaderModule $module
         * @param string $lang Language code
-        * @return string JSON object
+        * @return string JSON blob
         */
        private function generateMessageBlob( ResourceLoaderModule $module, 
$lang ) {
                $messages = array();

-- 
To view, visit https://gerrit.wikimedia.org/r/252870
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I89a14d7185877fae52791f6837883ed3a6749cd7
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to