From 6941fdffd5ce65d802f5acef789368cd7e34194b Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Tue, 14 Sep 2010 00:45:53 +0000 Subject: [PATCH] Reduced (dramatically) the number of database queries being performed to evaluate the last modified time of a module by only checking the mr_timestamp table when there are messages in the module. --- includes/ResourceLoaderModule.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/includes/ResourceLoaderModule.php b/includes/ResourceLoaderModule.php index 7f57e412d0..b8fbb16ecf 100644 --- a/includes/ResourceLoaderModule.php +++ b/includes/ResourceLoaderModule.php @@ -454,19 +454,20 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { $this->loaders, $this->getFileDependencies( $context->getSkin() ) ); - $filesMtime = max( array_map( 'filemtime', array_map( array( __CLASS__, 'remapFilename' ), $files ) ) ); - - // Get the mtime of the message blob - // TODO: This timestamp is queried a lot and queried separately for each module. Maybe it should be put in memcached? - $dbr = wfGetDb( DB_SLAVE ); - $msgBlobMtime = $dbr->selectField( 'msg_resource', 'mr_timestamp', array( - 'mr_resource' => $this->getName(), - 'mr_lang' => $context->getLanguage() - ), __METHOD__ - ); - $msgBlobMtime = $msgBlobMtime ? wfTimestamp( TS_UNIX, $msgBlobMtime ) : 0; - + // Only get the message timestamp if there are messages in the module + $msgBlobMtime = 0; + if ( count( $this->messages ) ) { + // Get the mtime of the message blob + // TODO: This timestamp is queried a lot and queried separately for each module. Maybe it should be put in memcached? + $dbr = wfGetDb( DB_SLAVE ); + $msgBlobMtime = $dbr->selectField( 'msg_resource', 'mr_timestamp', array( + 'mr_resource' => $this->getName(), + 'mr_lang' => $context->getLanguage() + ), __METHOD__ + ); + $msgBlobMtime = $msgBlobMtime ? wfTimestamp( TS_UNIX, $msgBlobMtime ) : 0; + } $this->modifiedTime[$context->getHash()] = max( $filesMtime, $msgBlobMtime ); return $this->modifiedTime[$context->getHash()]; } -- 2.20.1