Legoktm has uploaded a new change for review. https://gerrit.wikimedia.org/r/88919
Change subject: Store entire db to url mapping in memcache ...................................................................... Store entire db to url mapping in memcache MassMessage::getDBName now maps the entire dbname to url array when first called, then stores it both in memcache and in PHP. Change-Id: I861e92c03819254b41657c00107e263a5faf77ba --- M MassMessage.body.php 1 file changed, 19 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage refs/changes/19/88919/1 diff --git a/MassMessage.body.php b/MassMessage.body.php index 55cfb8a..131a5aa 100644 --- a/MassMessage.body.php +++ b/MassMessage.body.php @@ -91,22 +91,27 @@ */ public static function getDBName( $host ) { global $wgConf, $wgMemc; - $key = 'massmessage:urltodb:' . md5( $host ); // Don't use wfMemcKey since it splits cache per wiki - $data = $wgMemc->get( $key ); - if ( $data !== false ) { - return $data; - } - $dbs = $wgConf->getLocalDatabases(); - foreach ( $dbs as $dbname ) { - $url = WikiMap::getWiki( $dbname )->getCanonicalServer(); - $parse = wfParseUrl( $url ); - if ( $parse['host'] == $host ) { - // Cache it for a week - $wgMemc->set( $key, $dbname, 60 * 60 * 24 * 7 ); - return $dbname; + static $mapping = null; + if ( $mapping === null ) { + // Don't use wfMemcKey since it splits cache per wiki + $key = 'massmessage:urltodb'; + $data = $wgMemc->get( $key ); + if ( $data === false ) { + $dbs = $wgConf->getLocalDatabases(); + $mapping = array(); + foreach ( $dbs as $dbname ) { + $url = WikiMap::getWiki( $dbname )->getCanonicalServer(); + $parse = wfParseUrl( $url ); + $mapping[$parse['host']] = $dbname; + } + $wgMemc->set( $key, $mapping, 60 * 60 * 24 * 7 ); + } else { + $mapping = $data; } } - + if ( isset( $mapping[$host] ) ) { + return $mapping[$host]; + } return null; // Couldn't find anything } -- To view, visit https://gerrit.wikimedia.org/r/88919 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I861e92c03819254b41657c00107e263a5faf77ba Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MassMessage Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits