Working around a few possible deadlocks by sorting values
authorAlexander Ebert <ebert@woltlab.com>
Thu, 26 Mar 2015 18:08:42 +0000 (19:08 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 26 Mar 2015 18:08:42 +0000 (19:08 +0100)
wcfsetup/install/files/lib/data/user/notification/UserNotificationAction.class.php
wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php

index ea76e06ac7221127905361af1036cda80a50c44b..4079a706798907711971b78a9590332036e5e379 100644 (file)
@@ -112,6 +112,17 @@ class UserNotificationAction extends AbstractDatabaseObjectAction {
                        );
                }
                
+               usort($notifications, function ($a, $b) {
+                       if ($a['object']->notificationID == $b['object']->notificationID) {
+                               return 0;
+                       }
+                       else if ($a['object']->notificationID < $b['object']->notificationID) {
+                               return -1;
+                       }
+                       
+                       return 1;
+               });
+               
                // insert author
                $sql = "INSERT IGNORE INTO      wcf".WCF_N."_user_notification_author
                                                (notificationID, authorID, time)
index 5f73d89ddc9a45c80d0c34c5f037a96bfe49cd9e..de3c8617ffaa26d9e5303dab7c3b87178ee3156c 100644 (file)
@@ -162,6 +162,8 @@ class UserStorageHandler extends SingletonFactory {
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($field));
                
+               ksort($this->cache, SORT_NATURAL);
+               
                foreach ($this->cache as $userID => $fields) {
                        if (isset($fields[$field])) {
                                unset($this->cache[$userID][$field]);
@@ -181,6 +183,9 @@ class UserStorageHandler extends SingletonFactory {
                                WHERE           userID = ?
                                                AND field = ?";
                        $statement = WCF::getDB()->prepareStatement($sql);
+                       
+                       ksort($this->resetFields, SORT_NATURAL);
+                       
                        foreach ($this->resetFields as $userID => $fields) {
                                foreach ($fields as $field) {
                                        $statement->execute(array(
@@ -214,7 +219,11 @@ class UserStorageHandler extends SingletonFactory {
                                        VALUES          (?, ?, ?)";
                                $statement = WCF::getDB()->prepareStatement($sql);
                                
+                               ksort($this->updateFields, SORT_NATURAL);
+                               
                                foreach ($this->updateFields as $userID => $fieldValues) {
+                                       ksort($fieldValues, SORT_STRING);
+                                       
                                        foreach ($fieldValues as $field => $fieldValue) {
                                                $statement->execute(array(
                                                        $userID,