Migrate the important workers to the linear rebuild worker
authorAlexander Ebert <ebert@woltlab.com>
Sun, 9 Jun 2024 10:56:24 +0000 (12:56 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 9 Jun 2024 10:56:24 +0000 (12:56 +0200)
wcfsetup/install/files/lib/system/worker/AbstractLinearRebuildDataWorker.class.php
wcfsetup/install/files/lib/system/worker/CommentRebuildDataWorker.class.php
wcfsetup/install/files/lib/system/worker/CommentResponseRebuildDataWorker.class.php
wcfsetup/install/files/lib/system/worker/LikeRebuildDataWorker.class.php
wcfsetup/install/files/lib/system/worker/UserActivityPointItemsRebuildDataWorker.class.php
wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php

index 858183ed390ae114ed09bee0c7c31cfe3c4b4254..3de4344c31c214b14f61b297d92fe20e8836a96c 100644 (file)
@@ -45,7 +45,7 @@ abstract class AbstractLinearRebuildDataWorker extends AbstractRebuildDataWorker
         $statement = WCF::getDB()->prepare($sql);
         $statement->execute();
 
-        $this->count = $statement->fetchSingleColumn();
+        $this->count = $statement->fetchSingleColumn() ?: 0;
     }
 
     #[\Override]
index d71b68e674cc98de8466f16cb915d830281d94b0..e4c8c1b0fd54e469a04708e5b444af7d918c8224 100644 (file)
@@ -17,58 +17,26 @@ use wcf\system\WCF;
  * @copyright   2001-2019 WoltLab GmbH
  * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  */
-class CommentRebuildDataWorker extends AbstractRebuildDataWorker
+final class CommentRebuildDataWorker extends AbstractLinearRebuildDataWorker
 {
     /**
      * @inheritDoc
      */
     protected $limit = 500;
 
-    /**
-     * @var HtmlInputProcessor
-     */
-    protected $htmlInputProcessor;
-
     /**
      * @inheritDoc
      */
-    public function countObjects()
-    {
-        if ($this->count === null) {
-            $this->count = 0;
-            $sql = "SELECT  MAX(commentID) AS commentID
-                    FROM    wcf" . WCF_N . "_comment";
-            $statement = WCF::getDB()->prepareStatement($sql);
-            $statement->execute();
-            $row = $statement->fetchArray();
-            if ($row !== false) {
-                $this->count = $row['commentID'];
-            }
-        }
-    }
+    protected $objectListClassName = CommentList::class;
 
-    /**
-     * @inheritDoc
-     */
-    protected function initObjectList()
-    {
-        $this->objectList = new CommentList();
-        $this->objectList->sqlOrderBy = 'comment.commentID';
-    }
+    private HtmlInputProcessor $htmlInputProcessor;
 
-    /**
-     * @inheritDoc
-     */
+    #[\Override]
     public function execute()
     {
-        $this->objectList->getConditionBuilder()->add(
-            'comment.commentID BETWEEN ? AND ?',
-            [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]
-        );
-
         parent::execute();
 
-        if (!\count($this->objectList)) {
+        if (\count($this->getObjectList()) === 0) {
             return;
         }
 
@@ -124,12 +92,9 @@ class CommentRebuildDataWorker extends AbstractRebuildDataWorker
         WCF::getDB()->commitTransaction();
     }
 
-    /**
-     * @return HtmlInputProcessor
-     */
-    protected function getHtmlInputProcessor()
+    private function getHtmlInputProcessor(): HtmlInputProcessor
     {
-        if ($this->htmlInputProcessor === null) {
+        if (!isset($this->htmlInputProcessor)) {
             $this->htmlInputProcessor = new HtmlInputProcessor();
         }
 
index 6bca81d6436cb4fb7352b827b1ab17e91df6e6ae..cc9dc3527e0ff46e2e921050ed008f99c8ad1471 100644 (file)
@@ -17,58 +17,26 @@ use wcf\system\WCF;
  * @copyright   2001-2019 WoltLab GmbH
  * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  */
-class CommentResponseRebuildDataWorker extends AbstractRebuildDataWorker
+final class CommentResponseRebuildDataWorker extends AbstractLinearRebuildDataWorker
 {
     /**
      * @inheritDoc
      */
     protected $limit = 500;
 
-    /**
-     * @var HtmlInputProcessor
-     */
-    protected $htmlInputProcessor;
-
     /**
      * @inheritDoc
      */
-    public function countObjects()
-    {
-        if ($this->count === null) {
-            $this->count = 0;
-            $sql = "SELECT  MAX(responseID) AS responseID
-                    FROM    wcf" . WCF_N . "_comment_response";
-            $statement = WCF::getDB()->prepareStatement($sql);
-            $statement->execute();
-            $row = $statement->fetchArray();
-            if ($row !== false) {
-                $this->count = $row['responseID'];
-            }
-        }
-    }
+    protected $objectListClassName = CommentResponseList::class;
 
-    /**
-     * @inheritDoc
-     */
-    protected function initObjectList()
-    {
-        $this->objectList = new CommentResponseList();
-        $this->objectList->sqlOrderBy = 'comment_response.responseID';
-    }
+    private HtmlInputProcessor $htmlInputProcessor;
 
-    /**
-     * @inheritDoc
-     */
+    #[\Override]
     public function execute()
     {
-        $this->objectList->getConditionBuilder()->add(
-            'comment_response.responseID BETWEEN ? AND ?',
-            [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]
-        );
-
         parent::execute();
 
-        if (!\count($this->objectList)) {
+        if (\count($this->getObjectList()) === 0) {
             return;
         }
 
@@ -121,12 +89,9 @@ class CommentResponseRebuildDataWorker extends AbstractRebuildDataWorker
         WCF::getDB()->commitTransaction();
     }
 
-    /**
-     * @return HtmlInputProcessor
-     */
-    protected function getHtmlInputProcessor()
+    private function getHtmlInputProcessor(): HtmlInputProcessor
     {
-        if ($this->htmlInputProcessor === null) {
+        if (!isset($this->htmlInputProcessor)) {
             $this->htmlInputProcessor = new HtmlInputProcessor();
         }
 
index b505b984402d683a616cf72d3f736ddde6dc95df..6a3874b98adc93d718d502ad7db3feee4539fbea 100644 (file)
@@ -16,7 +16,7 @@ use wcf\system\WCF;
  *
  * @method  LikeList    getObjectList()
  */
-class LikeRebuildDataWorker extends AbstractRebuildDataWorker
+final class LikeRebuildDataWorker extends AbstractLinearRebuildDataWorker
 {
     /**
      * @inheritDoc
@@ -28,9 +28,7 @@ class LikeRebuildDataWorker extends AbstractRebuildDataWorker
      */
     protected $limit = 10000;
 
-    /**
-     * @inheritDoc
-     */
+    #[\Override]
     protected function initObjectList()
     {
         parent::initObjectList();
@@ -38,9 +36,7 @@ class LikeRebuildDataWorker extends AbstractRebuildDataWorker
         $this->objectList->sqlOrderBy = 'like_table.objectTypeID, like_table.objectID, like_table.likeID';
     }
 
-    /**
-     * @inheritDoc
-     */
+    #[\Override]
     public function execute()
     {
         parent::execute();
@@ -50,15 +46,19 @@ class LikeRebuildDataWorker extends AbstractRebuildDataWorker
             UserActivityPointHandler::getInstance()->reset('com.woltlab.wcf.like.activityPointEvent.receivedLikes');
 
             // reset like object data
-            $sql = "UPDATE  wcf" . WCF_N . "_like_object
+            $sql = "UPDATE  wcf1_like_object
                     SET     likes = 0,
                             dislikes = 0,
-                            cumulativeLikes = 0, 
+                            cumulativeLikes = 0,
                             cachedReactions = NULL";
-            $statement = WCF::getDB()->prepareStatement($sql);
+            $statement = WCF::getDB()->prepare($sql);
             $statement->execute();
         }
 
+        if (\count($this->getObjectList()) === 0) {
+            return;
+        }
+
         $itemsToUser = [];
         $likeObjectData = [];
         foreach ($this->objectList as $like) {
@@ -93,7 +93,7 @@ class LikeRebuildDataWorker extends AbstractRebuildDataWorker
         }
 
         // No objects are fetched. We can abort the execution.
-        if (empty($likeObjectData)) {
+        if ($likeObjectData === []) {
             return;
         }
 
@@ -114,29 +114,29 @@ class LikeRebuildDataWorker extends AbstractRebuildDataWorker
             $condition->add('objectTypeID = ?', [$objectTypeID]);
             $condition->add('objectID IN (?)', [\array_keys($objects)]);
             $sql = "SELECT  objectTypeID, objectID, objectUserID, likes, dislikes, cumulativeLikes, cachedReactions
-                    FROM    wcf" . WCF_N . "_like_object
+                    FROM    wcf1_like_object
                     " . $condition;
-            $objectStatement = WCF::getDB()->prepareStatement($sql);
+            $objectStatement = WCF::getDB()->prepare($sql);
             $objectStatement->execute($condition->getParameters());
             while ($row = $objectStatement->fetchArray()) {
                 $rows[$objectTypeID][$row['objectID']] = $row;
             }
         }
 
-        $sql = "INSERT INTO wcf" . WCF_N . "_like_object
+        $sql = "INSERT INTO wcf1_like_object
                             (objectTypeID, objectID, objectUserID, likes, dislikes, cumulativeLikes, cachedReactions)
                 VALUES      (?, ?, ?, ?, ?, ?, ?)";
-        $insertStatement = WCF::getDB()->prepareStatement($sql);
+        $insertStatement = WCF::getDB()->prepare($sql);
 
-        $sql = "UPDATE  wcf" . WCF_N . "_like_object
+        $sql = "UPDATE  wcf1_like_object
                 SET     objectUserID = ?,
                         likes = ?,
                         dislikes = 0,
-                        cumulativeLikes = ?, 
+                        cumulativeLikes = ?,
                         cachedReactions = ?
                 WHERE   objectTypeID = ?
                 AND     objectID = ?";
-        $updateStatement = WCF::getDB()->prepareStatement($sql);
+        $updateStatement = WCF::getDB()->prepare($sql);
 
         WCF::getDB()->beginTransaction();
         foreach ($likeObjectData as $objectTypeID => $objects) {
index ceff59952f8bf9e96bfd777460e456dadc8f42f0..1afd811596d3725726a6db2180492d509342bb91 100644 (file)
@@ -4,8 +4,6 @@ namespace wcf\system\worker;
 
 use wcf\data\user\UserList;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\event\EventHandler;
-use wcf\system\search\SearchIndexManager;
 use wcf\system\user\activity\point\UserActivityPointHandler;
 use wcf\system\WCF;
 
@@ -23,7 +21,7 @@ use wcf\system\WCF;
  *
  * @method  UserList    getObjectList()
  */
-class UserActivityPointItemsRebuildDataWorker extends AbstractRebuildDataWorker
+final class UserActivityPointItemsRebuildDataWorker extends AbstractLinearRebuildDataWorker
 {
     /**
      * @inheritDoc
@@ -35,50 +33,15 @@ class UserActivityPointItemsRebuildDataWorker extends AbstractRebuildDataWorker
      */
     protected $limit = 50;
 
-    #[\Override]
-    public function countObjects()
-    {
-        if ($this->count === null) {
-            $sql = "SELECT  MAX(userID) AS userID
-                    FROM    wcf1_user";
-            $statement = WCF::getDB()->prepare($sql);
-            $statement->execute();
-
-            $count = $statement->fetchSingleColumn();
-            $this->count = $count ?: 0;
-        }
-    }
-
-    #[\Override]
-    protected function initObjectList()
-    {
-        $this->objectList = new $this->objectListClassName();
-        $this->objectList->sqlOrderBy = 'user_table.userID';
-    }
-
     #[\Override]
     public function execute()
     {
-        $this->objectList->getConditionBuilder()->add(
-            'user_table.userID BETWEEN ? AND ?',
-            [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]
-        );
-
-        $this->objectList->readObjects();
+        parent::execute();
 
         if (\count($this->getObjectList()) === 0) {
             return;
         }
 
-        // The next two lines are copied from `AbstractRebuildDataWorker::execute()`
-        // to prevent event listeners from failing because the object list
-        // sometimes no longer contains objects.
-        //
-        // The return condition above is used to avoid the invocation of the
-        // event listeners. Do not call `parent::execute()`!
-        SearchIndexManager::getInstance()->beginBulkOperation();
-        EventHandler::getInstance()->fireAction($this, 'execute');
-
         // update activity points for positive reactions
         $reactionObjectType = UserActivityPointHandler::getInstance()
             ->getObjectTypeByName('com.woltlab.wcf.like.activityPointEvent.receivedLikes');
@@ -87,13 +50,13 @@ class UserActivityPointItemsRebuildDataWorker extends AbstractRebuildDataWorker
         $conditionBuilder->add('user_activity_point.objectTypeID = ?', [$reactionObjectType->objectTypeID]);
         $conditionBuilder->add('user_activity_point.userID IN (?)', [$this->getObjectList()->getObjectIDs()]);
 
-        $sql = "UPDATE      wcf" . WCF_N . "_user_activity_point user_activity_point
-                LEFT JOIN   wcf" . WCF_N . "_user user_table
+        $sql = "UPDATE      wcf1_user_activity_point user_activity_point
+                LEFT JOIN   wcf1_user user_table
                 ON          user_table.userID = user_activity_point.userID
                 SET         user_activity_point.items = user_table.likesReceived,
                             user_activity_point.activityPoints = user_activity_point.items * ?
                 " . $conditionBuilder;
-        $statement = WCF::getDB()->prepareStatement($sql);
+        $statement = WCF::getDB()->prepare($sql);
         $statement->execute(\array_merge(
             [$reactionObjectType->points],
             $conditionBuilder->getParameters()
index 4d6701972ef2674eacd33b9a39291c6b598bede1..a29b883aecf3d7ae2fe6c6cf0a0bec4462c7927d 100644 (file)
@@ -15,11 +15,9 @@ use wcf\data\user\UserProfileAction;
 use wcf\data\user\UserProfileList;
 use wcf\system\bbcode\BBCodeHandler;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\event\EventHandler;
 use wcf\system\exception\SystemException;
 use wcf\system\html\input\HtmlInputProcessor;
 use wcf\system\image\ImageHandler;
-use wcf\system\search\SearchIndexManager;
 use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\WCF;
 
@@ -32,7 +30,7 @@ use wcf\system\WCF;
  *
  * @method  UserList    getObjectList()
  */
-class UserRebuildDataWorker extends AbstractRebuildDataWorker
+final class UserRebuildDataWorker extends AbstractLinearRebuildDataWorker
 {
     /**
      * @inheritDoc
@@ -44,54 +42,26 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker
      */
     protected $limit = 50;
 
-    #[\Override]
-    public function countObjects()
-    {
-        if ($this->count === null) {
-            $sql = "SELECT  MAX(userID) AS userID
-                    FROM    wcf1_user";
-            $statement = WCF::getDB()->prepare($sql);
-            $statement->execute();
-
-            $count = $statement->fetchSingleColumn();
-            $this->count = $count ?: 0;
-        }
-    }
-
     #[\Override]
     protected function initObjectList()
     {
-        $this->objectList = new $this->objectListClassName();
+        parent::initObjectList();
+
         $this->objectList->sqlSelects = 'user_option_value.userOption' . User::getUserOptionID('aboutMe') . ' AS aboutMe';
         $this->objectList->sqlJoins = "
             LEFT JOIN   wcf" . WCF_N . "_user_option_value user_option_value
             ON          user_option_value.userID = user_table.userID";
-        $this->objectList->sqlOrderBy = 'user_table.userID';
     }
 
     #[\Override]
     public function execute()
     {
-        $this->objectList->getConditionBuilder()->add(
-            'user_table.userID BETWEEN ? AND ?',
-            [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]
-        );
-
-        $this->objectList->readObjects();
+        parent::execute();
 
         if (\count($this->getObjectList()) === 0) {
             return;
         }
 
-        // The next two lines are copied from `AbstractRebuildDataWorker::execute()`
-        // to prevent event listeners from failing because the object list
-        // sometimes no longer contains objects.
-        //
-        // The return condition above is used to avoid the invocation of the
-        // event listeners. Do not call `parent::execute()`!
-        SearchIndexManager::getInstance()->beginBulkOperation();
-        EventHandler::getInstance()->fireAction($this, 'execute');
-
         $users = $userIDs = [];
         foreach ($this->getObjectList() as $user) {
             $users[] = new UserEditor($user);
@@ -108,19 +78,19 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker
             // update article counter
             $conditionBuilder = new PreparedStatementConditionBuilder();
             $conditionBuilder->add('user_table.userID IN (?)', [$userIDs]);
-            $sql = "UPDATE  wcf" . WCF_N . "_user user_table
+            $sql = "UPDATE  wcf1_user user_table
                     SET     articles = (
                                 SELECT  COUNT(*)
-                                FROM    wcf" . WCF_N . "_article
+                                FROM    wcf1_article
                                 WHERE   userID = user_table.userID
                             )
                     " . $conditionBuilder;
-            $statement = WCF::getDB()->prepareStatement($sql);
+            $statement = WCF::getDB()->prepare($sql);
             $statement->execute($conditionBuilder->getParameters());
 
             // update like counter
             if (MODULE_LIKE) {
-                $sql = "UPDATE  wcf" . WCF_N . "_user user_table
+                $sql = "UPDATE  wcf1_user user_table
                         SET";
 
                 $reactionTypeIDs = \array_keys(ReactionTypeCache::getInstance()->getReactionTypes());
@@ -128,7 +98,7 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker
                     $sql .= "
                         likesReceived = (
                             SELECT  COUNT(*)
-                            FROM    wcf" . WCF_N . "_like
+                            FROM    wcf1_like
                             WHERE   objectUserID = user_table.userID
                                 AND reactionTypeID IN (" . \implode(',', $reactionTypeIDs) . ")
                         )";
@@ -137,34 +107,34 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker
                 }
 
                 $sql .= " " . $conditionBuilder;
-                $statement = WCF::getDB()->prepareStatement($sql);
+                $statement = WCF::getDB()->prepare($sql);
                 $statement->execute($conditionBuilder->getParameters());
             }
 
             // update trophy points
             if (MODULE_TROPHY) {
-                $sql = "UPDATE  wcf" . WCF_N . "_user user_table
+                $sql = "UPDATE  wcf1_user user_table
                         SET     trophyPoints = (
                                     SELECT      COUNT(*)
-                                    FROM        wcf" . WCF_N . "_user_trophy user_trophy
-                                    LEFT JOIN   wcf" . WCF_N . "_trophy trophy
+                                    FROM        wcf1_user_trophy user_trophy
+                                    LEFT JOIN   wcf1_trophy trophy
                                     ON          user_trophy.trophyID = trophy.trophyID
-                                    LEFT JOIN   wcf" . WCF_N . "_category trophy_category
+                                    LEFT JOIN   wcf1_category trophy_category
                                     ON          trophy.categoryID = trophy_category.categoryID
                                     WHERE           user_trophy.userID = user_table.userID
                                                 AND trophy.isDisabled = 0
                                                 AND trophy_category.isDisabled = 0
                                 )
                         " . $conditionBuilder;
-                $statement = WCF::getDB()->prepareStatement($sql);
+                $statement = WCF::getDB()->prepare($sql);
                 $statement->execute($conditionBuilder->getParameters());
             }
 
             // update signatures and about me
-            $sql = "UPDATE  wcf" . WCF_N . "_user_option_value
+            $sql = "UPDATE  wcf1_user_option_value
                     SET     userOption" . User::getUserOptionID('aboutMe') . " = ?
                     WHERE   userID = ?";
-            $statement = WCF::getDB()->prepareStatement($sql);
+            $statement = WCF::getDB()->prepare($sql);
 
             // retrieve permissions
             $userIDs = [];