Optimize JobQueue utilization in UserGroupMembership::insert()
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 5 Jul 2019 23:27:43 +0000 (16:27 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 5 Jul 2019 23:27:43 +0000 (16:27 -0700)
Change-Id: I20d6d753221616817150f34307a8ffaf1bb74ae8

includes/user/UserGroupMembership.php

index e06df9f..eb55567 100644 (file)
@@ -159,7 +159,15 @@ class UserGroupMembership {
                }
 
                // Purge old, expired memberships from the DB
-               JobQueueGroup::singleton()->push( new UserGroupExpiryJob() );
+               $hasExpiredRow = $dbw->selectField(
+                       'user_groups',
+                       '1',
+                       [ 'ug_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
+                       __METHOD__
+               );
+               if ( $hasExpiredRow ) {
+                       JobQueueGroup::singleton()->lazyPush( new UserGroupExpiryJob() );
+               }
 
                // Check that the values make sense
                if ( $this->group === null ) {