Some small optimizations
authorMarcel Werk <burntime@woltlab.com>
Fri, 13 Jan 2012 17:57:39 +0000 (18:57 +0100)
committerMarcel Werk <burntime@woltlab.com>
Fri, 13 Jan 2012 17:57:39 +0000 (18:57 +0100)
wcfsetup/install/files/lib/data/user/User.class.php
wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php
wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php

index 9e5ea6066b6c94c4d7a7fe41a774faee5822940f..48b570274d53184f95b3561333089fffee2c5af7 100644 (file)
@@ -114,10 +114,10 @@ final class User extends DatabaseObject implements IRouteController {
                        }
                        else {
                                // load storage data
-                               UserStorageHandler::getInstance()->loadStorage(array($this->userID), 1);
+                               UserStorageHandler::getInstance()->loadStorage(array($this->userID));
                                
                                // get group ids
-                               $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'groupIDs', 1);
+                               $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'groupIDs');
                                
                                // cache does not exist or is outdated
                                if ($data[$this->userID] === null) {
@@ -155,10 +155,10 @@ final class User extends DatabaseObject implements IRouteController {
                        }
                        else {
                                // load storage data
-                               UserStorageHandler::getInstance()->loadStorage(array($this->userID), 1);
+                               UserStorageHandler::getInstance()->loadStorage(array($this->userID));
                                
                                // get language ids
-                               $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'languageIDs', 1);
+                               $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'languageIDs');
                                
                                // cache does not exist or is outdated
                                if ($data[$this->userID] === null) {
index 4337b965fe5a3637ffea02538ff2c1806115a0a8..2b1f555062b0ac5d23a62f6c0c2d12be4ee551cb 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\user\collapsible\content;
 use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
 
@@ -69,17 +70,32 @@ class UserCollapsibleContentHandler extends SingletonFactory {
                        $this->collapsedContent[$objectTypeID] = array();
                        
                        if (WCF::getUser()->userID) {
-                               $sql = "SELECT  objectID
-                                       FROM    wcf".WCF_N."_user_collapsible_content
-                                       WHERE   objectTypeID = ?
-                                       AND userID = ?";
-                               $statement = WCF::getDB()->prepareStatement($sql);
-                               $statement->execute(array(
-                                       $objectTypeID,
-                                       WCF::getUser()->userID
-                               ));
-                               while ($row = $statement->fetchArray()) {
-                                       $this->collapsedContent[$objectTypeID][] = $row['objectID'];
+                               // get data from storage
+                               UserStorageHandler::getInstance()->loadStorage(array(WCF::getUser()->userID));
+                                               
+                               // get ids
+                               $data = UserStorageHandler::getInstance()->getStorage(array(WCF::getUser()->userID), 'collapsedContent-'.$objectTypeID);
+                                       
+                               // cache does not exist or is outdated
+                               if ($data[WCF::getUser()->userID] === null) {
+                                       $sql = "SELECT  objectID
+                                               FROM    wcf".WCF_N."_user_collapsible_content
+                                               WHERE   objectTypeID = ?
+                                                       AND userID = ?";
+                                       $statement = WCF::getDB()->prepareStatement($sql);
+                                       $statement->execute(array(
+                                               $objectTypeID,
+                                               WCF::getUser()->userID
+                                       ));
+                                       while ($row = $statement->fetchArray()) {
+                                               $this->collapsedContent[$objectTypeID][] = $row['objectID'];
+                                       }
+                                       
+                                       // update storage data
+                                       UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'collapsedContent-'.$objectTypeID, serialize($this->collapsedContent[$objectTypeID]), 1);
+                               }
+                               else {
+                                       $this->collapsedContent[$objectTypeID] = @unserialize($data[WCF::getUser()->userID]);
                                }
                        }
                        else {
@@ -127,6 +143,9 @@ class UserCollapsibleContentHandler extends SingletonFactory {
                                        WCF::getUser()->userID
                                ));
                        }
+                       
+                       // reset storage
+                       UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'collapsedContent-'.$objectTypeID, 1);
                }
                else {
                        $collapsedContent = WCF::getSession()->getVar('collapsedContent');
@@ -161,6 +180,9 @@ class UserCollapsibleContentHandler extends SingletonFactory {
                                $objectID,
                                WCF::getUser()->userID
                        ));
+                       
+                       // reset storage
+                       UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'collapsedContent-'.$objectTypeID, 1);
                }
                else {
                        $collapsedContent = WCF::getSession()->getVar('collapsedContent');
@@ -195,6 +217,9 @@ class UserCollapsibleContentHandler extends SingletonFactory {
                                $objectTypeID,
                                WCF::getUser()->userID
                        ));
+                       
+                       // reset storage
+                       UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'collapsedContent-'.$objectTypeID, 1);
                }
                else {
                        $collapsedContent = WCF::getSession()->getVar('collapsedContent');
index 56480536fbf3edbdd79b73f7337d3716b69bfefb..6cce93e201b90cd846c566037dcce17ea7b580fa 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\user\storage;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\package\PackageDependencyHandler;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
 
@@ -42,7 +43,7 @@ class UserStorageHandler extends SingletonFactory {
        public function loadStorage(array $userIDs, $packageID = PACKAGE_ID) {
                $tmp = array();
                foreach ($userIDs as $userID) {
-                       if (!isset($this->cache[$userID][$packageID])) $tmp[] = $userID;
+                       if (!isset($this->cache[$userID])) $tmp[] = $userID;
                }
                
                // ignore users whose storage data is already loaded
@@ -50,7 +51,7 @@ class UserStorageHandler extends SingletonFactory {
                
                $conditions = new PreparedStatementConditionBuilder();
                $conditions->add("userID IN (?)", array($tmp));
-               $conditions->add("packageID = ?", array($packageID));
+               $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies($packageID)));
                
                $sql = "SELECT  *
                        FROM    wcf".WCF_N."_user_storage
@@ -62,11 +63,7 @@ class UserStorageHandler extends SingletonFactory {
                                $this->cache[$row['userID']] = array();
                        }
                        
-                       if (!isset($this->cache[$row['userID']][$row['packageID']])) {
-                               $this->cache[$row['userID']][$row['packageID']] = array();
-                       }
-                       
-                       $this->cache[$row['userID']][$row['packageID']][$row['field']] = $row['fieldValue'];
+                       $this->cache[$row['userID']][$row['field']] = $row['fieldValue'];
                }
        }
        
@@ -75,15 +72,14 @@ class UserStorageHandler extends SingletonFactory {
         * 
         * @param       array<integer>  $userIDs
         * @param       string          $field
-        * @param       integer         $packageID
         * @return      array<array>
         */
-       public function getStorage(array $userIDs, $field, $packageID = PACKAGE_ID) {
+       public function getStorage(array $userIDs, $field) {
                $data = array();
                
                foreach ($userIDs as $userID) {
-                       if (isset($this->cache[$userID][$packageID][$field])) {
-                               $data[$userID] = $this->cache[$userID][$packageID][$field];
+                       if (isset($this->cache[$userID][$field])) {
+                               $data[$userID] = $this->cache[$userID][$field];
                        }
                        else {
                                $data[$userID] = null;
@@ -109,11 +105,7 @@ class UserStorageHandler extends SingletonFactory {
                        $this->cache[$userID] = array();
                }
                
-               if (!isset($this->cache[$userID][$packageID])) {
-                       $this->cache[$userID][$packageID] = array();
-               }
-               
-               $this->cache[$userID][$packageID][$field] = $fieldValue;
+               $this->cache[$userID][$field] = $fieldValue;
                
                // flag key as outdated
                self::reset(array($userID), $field, $packageID);