Locally caching default values of user options
authorAlexander Ebert <ebert@woltlab.com>
Mon, 8 Jul 2013 17:29:25 +0000 (19:29 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 8 Jul 2013 17:29:25 +0000 (19:29 +0200)
wcfsetup/install/files/lib/data/user/UserEditor.class.php

index 265fe9f79e24d684f06520691acbf2d95d76d0db..34a4885ab9afc6b0bc289aeadfba250922e50354 100644 (file)
@@ -26,6 +26,12 @@ class UserEditor extends DatabaseObjectEditor implements IEditableCachedObject {
         */
        protected static $baseClass = 'wcf\data\user\User';
        
+       /**
+        * list of user options default values
+        * @var array
+        */
+       protected static $userOptionDefaultValues = null;
+       
        /**
         * @see wcf\data\IEditableObject::create()
         */
@@ -82,23 +88,25 @@ class UserEditor extends DatabaseObjectEditor implements IEditableCachedObject {
         * @param       integer         $userID
         */
        protected static function createUserOptions($userID) {
-               $userOptions = array();
-               
                // fetch default values
-               $sql = "SELECT  optionID, defaultValue
-                       FROM    wcf".WCF_N."_user_option";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute();
-               while ($row = $statement->fetchArray()) {
-                       if (!empty($row['defaultValue'])) {
-                               $userOptions[$row['optionID']] = $row['defaultValue'];
+               if (self::$userOptionDefaultValues === null) {
+                       self::$userOptionDefaultValues = array();
+                       
+                       $sql = "SELECT  optionID, defaultValue
+                               FROM    wcf".WCF_N."_user_option";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute();
+                       while ($row = $statement->fetchArray()) {
+                               if (!empty($row['defaultValue'])) {
+                                       self::$userOptionDefaultValues[$row['optionID']] = $row['defaultValue'];
+                               }
                        }
                }
                
                // insert default values
                $keys = $values = '';
                $statementParameters = array($userID);
-               foreach ($userOptions as $optionID => $optionValue) {
+               foreach (self::$userOptionDefaultValues as $optionID => $optionValue) {
                        $keys .= ', userOption'.$optionID;
                        $values .= ', ?';
                        $statementParameters[] = $optionValue;