Performance optimization for trophy assignment
authorMarcel Werk <burntime@woltlab.com>
Fri, 15 Jun 2018 10:01:22 +0000 (12:01 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 15 Jun 2018 10:01:22 +0000 (12:01 +0200)
com.woltlab.wcf/cronjob.xml
wcfsetup/install/files/lib/system/cronjob/AssignTrophiesCronjob.class.php
wcfsetup/install/files/lib/system/trophy/condition/TrophyConditionHandler.class.php

index ed91399e9d36bb2530a0844c4a0e64fe5da2de2e..848df2086bb6c737f2f3eefa608efc69da44252e 100644 (file)
                        <classname>wcf\system\cronjob\AssignTrophiesCronjob</classname>
                        <description>Assign trophies based on rules</description>
                        <description language="de">Ordnet Trophäen aufgrund der Regeln zu</description>
-                       <startminute>*/15</startminute>
+                       <startminute>*/5</startminute>
                        <starthour>*</starthour>
                        <startdom>*</startdom>
                        <startmonth>*</startmonth>
index 890f26eef743ae6b763ac7f0fd64a573ee2ff8a6..93031400dbf48d2481164d2fbc54031d18e503bd 100644 (file)
@@ -19,6 +19,8 @@ class AssignTrophiesCronjob extends AbstractCronjob {
        public function execute(Cronjob $cronjob) {
                parent::execute($cronjob);
                
-               TrophyConditionHandler::getInstance()->assignTrophies(50);
+               if (MODULE_TROPHY) {
+                       TrophyConditionHandler::getInstance()->assignTrophies(100);
+               }
        }
 }
index 551fcb811d7facd1d4fe36517c341d7384657956..b5d356db6fe58078e7b46164539287c0df6d9606 100644 (file)
@@ -5,7 +5,6 @@ use wcf\data\object\type\ObjectTypeCache;
 use wcf\data\trophy\Trophy;
 use wcf\data\trophy\TrophyList;
 use wcf\data\user\trophy\UserTrophyAction;
-use wcf\data\user\User;
 use wcf\data\user\UserList;
 use wcf\system\SingletonFactory;
 
@@ -70,13 +69,13 @@ class TrophyConditionHandler extends SingletonFactory {
                
                $i = 0;
                foreach ($trophyList as $trophy) {
-                       $users = $this->getUsers($trophy);
+                       $userIDs = $this->getUserIDs($trophy);
                        
-                       foreach ($users as $user) {
+                       foreach ($userIDs as $userID) {
                                (new UserTrophyAction([], 'create', [
                                        'data' => [
                                                'trophyID' => $trophy->trophyID,
-                                               'userID' => $user->userID,
+                                               'userID' => $userID,
                                                'time' => TIME_NOW
                                        ]
                                ]))->executeAction();
@@ -90,9 +89,9 @@ class TrophyConditionHandler extends SingletonFactory {
         * Returns the users who fulfill all conditions of the given trophy.
         *
         * @param       Trophy          $trophy
-        * @return      User[]
+        * @return      integer[]
         */
-       private function getUsers(Trophy $trophy) {
+       private function getUserIDs(Trophy $trophy) {
                $userList = new UserList();
                
                $conditions = $trophy->getConditions();
@@ -102,8 +101,8 @@ class TrophyConditionHandler extends SingletonFactory {
                
                // prevent multiple awards from a trophy for a user 
                $userList->getConditionBuilder()->add('user_table.userID NOT IN (SELECT userID FROM wcf'.WCF_N.'_user_trophy WHERE trophyID IN (?))', [$trophy->trophyID]);
-               $userList->readObjects();
+               $userList->readObjectIDs();
                
-               return $userList->getObjects();
+               return $userList->getObjectIDs();
        }
 }