Make JobQueueAggregator::doNotifyQueueNonEmpty() avoid queries
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 11 Nov 2015 21:50:35 +0000 (13:50 -0800)
committerReedy <reedy@wikimedia.org>
Sun, 15 Nov 2015 20:16:31 +0000 (20:16 +0000)
Avoid 2 of the 3 queries in doNotifyQueueNonEmpty(), the ones
that register the queue, once such a command has been done in
the request already.

Change-Id: I58553f0c56660f05a3e3000065270baebb8cbb62

includes/jobqueue/aggregator/JobQueueAggregatorRedis.php

index f8a0040..250947a 100644 (file)
 class JobQueueAggregatorRedis extends JobQueueAggregator {
        /** @var RedisConnectionPool */
        protected $redisPool;
-
        /** @var array List of Redis server addresses */
        protected $servers;
+       /** @var bool */
+       protected $registeredQueue = false;
 
        /**
         * @param array $params Possible keys:
@@ -80,11 +81,16 @@ class JobQueueAggregatorRedis extends JobQueueAggregator {
                }
                try {
                        $conn->multi( Redis::PIPELINE );
-                       $conn->hSetNx( $this->getQueueTypesKey(), $type, 'enabled' );
-                       $conn->sAdd( $this->getWikiSetKey(), $wiki );
+                       if ( !$this->registeredQueue ) {
+                               // Make sure the queue is registered as existing
+                               $conn->hSetNx( $this->getQueueTypesKey(), $type, 'enabled' );
+                               $conn->sAdd( $this->getWikiSetKey(), $wiki );
+                       }
                        $conn->hSet( $this->getReadyQueueKey(), $this->encQueueName( $type, $wiki ), time() );
                        $conn->exec();
 
+                       $this->registeredQueue = true;
+
                        return true;
                } catch ( RedisException $e ) {
                        $this->handleException( $conn, $e );