Automatically de-duplicate EnqueueJob jobs when possible
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 3 Aug 2015 19:46:30 +0000 (12:46 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 3 Aug 2015 19:46:30 +0000 (12:46 -0700)
Bug: T107792
Change-Id: I1e7fe5d5a6fed7b9a0dd4482ef3fc3a260033109

includes/jobqueue/jobs/EnqueueJob.php

index ca597ca..a3b6b96 100644 (file)
@@ -59,6 +59,8 @@ final class EnqueueJob extends Job {
         * @return EnqueueJob
         */
        public static function newFromJobsByWiki( array $jobsByWiki ) {
+               $deduplicate = true;
+
                $jobMapsByWiki = array();
                foreach ( $jobsByWiki as $wiki => $jobs ) {
                        $jobMapsByWiki[$wiki] = array();
@@ -68,10 +70,16 @@ final class EnqueueJob extends Job {
                                } else {
                                        throw new InvalidArgumentException( "Jobs must be of type JobSpecification." );
                                }
+                               $deduplicate = $deduplicate && $job->ignoreDuplicates();
                        }
                }
 
-               return new self( Title::newMainPage(), array( 'jobsByWiki' => $jobMapsByWiki ) );
+               $eJob = new self( Title::newMainPage(), array( 'jobsByWiki' => $jobMapsByWiki ) );
+               // If *all* jobs to be pushed are to be de-duplicated (a common case), then
+               // de-duplicate this whole job itself to avoid build up in high traffic cases
+               $eJob->removeDuplicates = $deduplicate;
+
+               return $eJob;
        }
 
        public function run() {