X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fcache%2FMessageBlobStore.php;h=ab7e1717c5e47319d21a9bb2f9d5c24693945654;hb=20c699b08ad8886bcc29d30148d8478ccd220b3d;hp=63d8c7e4731a593064e1f21c866b5cfe513009c0;hpb=c1f49bc7ce0c72ccaf0de6ad1f86c6c955766eca;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/cache/MessageBlobStore.php b/includes/cache/MessageBlobStore.php index 63d8c7e473..ab7e1717c5 100644 --- a/includes/cache/MessageBlobStore.php +++ b/includes/cache/MessageBlobStore.php @@ -1,6 +1,6 @@ resourceloader = $resourceloader; + } + /** * Get the singleton instance * @@ -131,29 +141,14 @@ class MessageBlobStore { array( 'IGNORE' ) ); - if ( $success ) { - if ( $dbw->affectedRows() == 0 ) { - // Blob was already present, fetch it - $blob = $dbw->selectField( 'msg_resource', 'mr_blob', array( - 'mr_resource' => $name, - 'mr_lang' => $lang, - ), - __METHOD__ - ); - } else { - // Update msg_resource_links - $rows = array(); - - foreach ( $module->getMessages() as $key ) { - $rows[] = array( - 'mrl_resource' => $name, - 'mrl_message' => $key - ); - } - $dbw->insert( 'msg_resource_links', $rows, - __METHOD__, array( 'IGNORE' ) - ); - } + if ( $success && $dbw->affectedRows() == 0 ) { + // Blob was already present, fetch it + $blob = $dbw->selectField( 'msg_resource', 'mr_blob', array( + 'mr_resource' => $name, + 'mr_lang' => $lang, + ), + __METHOD__ + ); } } catch ( DBError $e ) { wfDebug( __METHOD__ . " failed to update DB: $e\n" ); @@ -180,8 +175,6 @@ class MessageBlobStore { return null; } - // Save the old and new blobs for later - $oldBlob = $row->mr_blob; $newBlob = $this->generateMessageBlob( $module, $lang ); try { @@ -196,36 +189,6 @@ class MessageBlobStore { array( array( 'mr_resource', 'mr_lang' ) ), $newRow, __METHOD__ ); - - // Figure out which messages were added and removed - $oldMessages = array_keys( FormatJson::decode( $oldBlob, true ) ); - $newMessages = array_keys( FormatJson::decode( $newBlob, true ) ); - $added = array_diff( $newMessages, $oldMessages ); - $removed = array_diff( $oldMessages, $newMessages ); - - // Delete removed messages, insert added ones - if ( $removed ) { - $dbw->delete( 'msg_resource_links', array( - 'mrl_resource' => $name, - 'mrl_message' => $removed - ), __METHOD__ - ); - } - - $newLinksRows = array(); - - foreach ( $added as $message ) { - $newLinksRows[] = array( - 'mrl_resource' => $name, - 'mrl_message' => $message - ); - } - - if ( $newLinksRows ) { - $dbw->insert( 'msg_resource_links', $newLinksRows, __METHOD__, - array( 'IGNORE' ) // just in case - ); - } } catch ( Exception $e ) { wfDebug( __METHOD__ . " failed to update DB: $e\n" ); } @@ -273,26 +236,36 @@ class MessageBlobStore { } } while ( count( $updates ) ); - // No need to update msg_resource_links because we didn't add - // or remove any messages, we just changed their contents. } catch ( Exception $e ) { wfDebug( __METHOD__ . " failed to update DB: $e\n" ); } } public function clear() { - // TODO: Give this some more thought try { // Not using TRUNCATE, because that needs extra permissions, // which maybe not granted to the database user. $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'msg_resource', '*', __METHOD__ ); - $dbw->delete( 'msg_resource_links', '*', __METHOD__ ); } catch ( Exception $e ) { wfDebug( __METHOD__ . " failed to update DB: $e\n" ); } } + /** + * @return ResourceLoader + */ + protected function getResourceLoader() { + // For back-compat this class supports instantiation without passing ResourceLoader + // Lazy-initialise this property because most callers don't need it. + if ( $this->resourceloader === null ) { + wfDebug( __CLASS__ . ' created without a ResourceLoader instance' ); + $this->resourceloader = new ResourceLoader(); + } + + return $this->resourceloader; + } + /** * Create an update queue for updateMessage() * @@ -304,11 +277,15 @@ class MessageBlobStore { $dbw = wfGetDB( DB_MASTER ); if ( is_null( $prevUpdates ) ) { + $rl = $this->getResourceLoader(); + $moduleNames = $rl->getModulesByMessage( $key ); // Fetch all blobs referencing $key $res = $dbw->select( - array( 'msg_resource', 'msg_resource_links' ), + array( 'msg_resource' ), array( 'mr_resource', 'mr_lang', 'mr_blob', 'mr_timestamp' ), - array( 'mrl_message' => $key, 'mr_resource=mrl_resource' ), + array( + 'mr_resource' => $moduleNames, + ), __METHOD__ ); } else { @@ -374,7 +351,6 @@ class MessageBlobStore { return array(); } - $config = $resourceLoader->getConfig(); $retval = array(); $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( 'msg_resource', @@ -390,13 +366,10 @@ class MessageBlobStore { throw new MWException( __METHOD__ . ' passed an invalid module name' ); } - // Update the module's blobs if the set of messages changed or if the blob is - // older than the CacheEpoch setting - $keys = array_keys( FormatJson::decode( $row->mr_blob, true ) ); - $values = array_values( array_unique( $module->getMessages() ) ); - if ( $keys !== $values - || wfTimestamp( TS_MW, $row->mr_timestamp ) <= $config->get( 'CacheEpoch' ) - ) { + // Update the module's blob if the list of messages changed + $blobKeys = array_keys( FormatJson::decode( $row->mr_blob, true ) ); + $moduleMsgs = array_values( array_unique( $module->getMessages() ) ); + if ( $blobKeys !== $moduleMsgs ) { $retval[$row->mr_resource] = $this->updateModule( $row->mr_resource, $module, $lang ); } else { $retval[$row->mr_resource] = $row->mr_blob;