From 65361f8e0bb308473fc4c824022d168e924395d6 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 15 Jun 2018 12:01:22 +0200 Subject: [PATCH] Performance optimization for trophy assignment --- com.woltlab.wcf/cronjob.xml | 2 +- .../cronjob/AssignTrophiesCronjob.class.php | 4 +++- .../condition/TrophyConditionHandler.class.php | 15 +++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/com.woltlab.wcf/cronjob.xml b/com.woltlab.wcf/cronjob.xml index ed91399e9d..848df2086b 100644 --- a/com.woltlab.wcf/cronjob.xml +++ b/com.woltlab.wcf/cronjob.xml @@ -233,7 +233,7 @@ wcf\system\cronjob\AssignTrophiesCronjob Assign trophies based on rules Ordnet Trophäen aufgrund der Regeln zu - */15 + */5 * * * diff --git a/wcfsetup/install/files/lib/system/cronjob/AssignTrophiesCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/AssignTrophiesCronjob.class.php index 890f26eef7..93031400db 100644 --- a/wcfsetup/install/files/lib/system/cronjob/AssignTrophiesCronjob.class.php +++ b/wcfsetup/install/files/lib/system/cronjob/AssignTrophiesCronjob.class.php @@ -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); + } } } diff --git a/wcfsetup/install/files/lib/system/trophy/condition/TrophyConditionHandler.class.php b/wcfsetup/install/files/lib/system/trophy/condition/TrophyConditionHandler.class.php index 551fcb811d..b5d356db6f 100644 --- a/wcfsetup/install/files/lib/system/trophy/condition/TrophyConditionHandler.class.php +++ b/wcfsetup/install/files/lib/system/trophy/condition/TrophyConditionHandler.class.php @@ -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(); } } -- 2.20.1