Massively improve performance of ConversationMessageRebuildDataWorker
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 14 Apr 2015 20:06:52 +0000 (22:06 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 14 Apr 2015 20:06:52 +0000 (22:06 +0200)
see WoltLab/com.woltlab.wcf.exporter@04f6f92fae9c2ae03ea7c5fe688e05e1cc260c92

files/lib/system/worker/ConversationMessageRebuildDataWorker.class.php

index 5b1e2d6142ddaa494afe819c7379003d25aa973d..da4f169eb75077d7751425f8641cef01228d980c 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\worker;
 use wcf\data\conversation\message\ConversationMessageEditor;
+use wcf\data\conversation\message\ConversationMessageList;
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\search\SearchIndexManager;
@@ -18,21 +19,30 @@ use wcf\system\WCF;
  */
 class ConversationMessageRebuildDataWorker extends AbstractRebuildDataWorker {
        /**
-        * @see \wcf\system\worker\AbstractRebuildDataWorker::$objectListClassName
+        * @see \wcf\system\worker\AbstractWorker::$limit
         */
-       protected $objectListClassName = 'wcf\data\conversation\message\ConversationMessageList';
+       protected $limit = 500;
        
        /**
-        * @see \wcf\system\worker\AbstractWorker::$limit
+        * @see \wcf\system\worker\IWorker::countObjects()
         */
-       protected $limit = 500;
+       public function countObjects() {
+               if ($this->count === null) {
+                       $this->count = 0;
+                       $sql = "SELECT  MAX(messageID) AS messageID
+                               FROM    wcf".WCF_N."_conversation_message";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute();
+                       $row = $statement->fetchArray();
+                       if ($row !== false) $this->count = $row['messageID'];
+               }
+       }
        
        /**
         * @see \wcf\system\worker\AbstractRebuildDataWorker::initObjectList
         */
        protected function initObjectList() {
-               parent::initObjectList();
-               
+               $this->objectList = new ConversationMessageList();
                $this->objectList->sqlOrderBy = 'conversation_message.messageID';
                $this->objectList->sqlSelects = 'conversation.subject';
                $this->objectList->sqlJoins = 'LEFT JOIN wcf'.WCF_N.'_conversation conversation ON (conversation.firstMessageID = conversation_message.messageID)';
@@ -42,6 +52,8 @@ class ConversationMessageRebuildDataWorker extends AbstractRebuildDataWorker {
         * @see \wcf\system\worker\IWorker::execute()
         */
        public function execute() {
+               $this->objectList->getConditionBuilder()->add('conversation_message.messageID BETWEEN ? AND ?', array($this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit));
+               
                parent::execute();
                
                if (!$this->loopCount) {