No point in fetching the result in Database::unlock() if we're not using it anyway.
[lhc/web/wiklou.git] / maintenance / nextJobDB.php
index 3073227..6af5cbe 100644 (file)
@@ -1,7 +1,9 @@
 <?php
-
-/*
+/**
  * Pick a database that has pending jobs
+ *
+ * @file
+ * @ingroup Maintenance
  */
 
 $options = array( 'type'  );
@@ -12,22 +14,22 @@ $type = isset($options['type'])
                ? $options['type']
                : false;
 
-$pendingDBs = $wgMemc->get( 'jobqueue:dbs' );
+$mckey = $type === false
+            ? "jobqueue:dbs"
+            : "jobqueue:dbs:$type";
+
+$pendingDBs = $wgMemc->get( $mckey );
 if ( !$pendingDBs ) {
        $pendingDBs = array();
        # Cross-reference DBs by master DB server
        $dbsByMaster = array();
-       $defaultMaster = $wgAlternateMaster['DEFAULT'];
        foreach ( $wgLocalDatabases as $db ) {
-               if ( isset( $wgAlternateMaster[$db] ) ) {
-                       $dbsByMaster[$wgAlternateMaster[$db]][] = $db;
-               } else {
-                       $dbsByMaster[$defaultMaster][] = $db;
-               }
+               $lb = wfGetLB( $db );
+               $dbsByMaster[$lb->getServerName(0)][] = $db;
        }
 
        foreach ( $dbsByMaster as $master => $dbs ) {
-               $dbConn = new Database( $master, $wgDBuser, $wgDBpassword );
+               $dbConn = wfGetDB( DB_MASTER, array(), $dbs[0] );
                $stype = $dbConn->addQuotes($type);
 
                # Padding row for MySQL bug
@@ -39,7 +41,7 @@ if ( !$pendingDBs ) {
                        if ($type === false)
                                $sql .= "(SELECT '$dbName' FROM `$dbName`.job LIMIT 1)";
                        else
-                               $sql .= "(SELECT '$dbName' FROM `$dbName`.job WHERE job_cmd='$stype' LIMIT 1)";
+                               $sql .= "(SELECT '$dbName' FROM `$dbName`.job WHERE job_cmd=$stype LIMIT 1)";
                }
                $res = $dbConn->query( $sql, 'nextJobDB.php' );
                $row = $dbConn->fetchRow( $res ); // discard padding row
@@ -48,11 +50,11 @@ if ( !$pendingDBs ) {
                }
        }
 
-       $wgMemc->set( 'jobqueue:dbs', $pendingDBs, 300 );
+       $wgMemc->set( $mckey, $pendingDBs, 300 );
 }
 
 if ( $pendingDBs ) {
        echo $pendingDBs[mt_rand(0, count( $pendingDBs ) - 1)];
 }
 
-?>
+