From: Matthias Schmidt Date: Sun, 23 Jun 2019 13:39:25 +0000 (+0200) Subject: Support firing multiple activity event at once X-Git-Tag: 5.2.0_Alpha_3~26^2~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=23ad7be0b1ae09a42021162eecc7cd943e965445;p=GitHub%2FWoltLab%2FWCF.git Support firing multiple activity event at once --- diff --git a/wcfsetup/install/files/lib/system/user/activity/event/UserActivityEventHandler.class.php b/wcfsetup/install/files/lib/system/user/activity/event/UserActivityEventHandler.class.php index b2ec8d62ec..906a907ce3 100644 --- a/wcfsetup/install/files/lib/system/user/activity/event/UserActivityEventHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/activity/event/UserActivityEventHandler.class.php @@ -99,6 +99,49 @@ class UserActivityEventHandler extends SingletonFactory { return $returnValues['returnValues']; } + /** + * Fires multiple new activity events for the same activity event type. + * + * This method is intended for bulk processing. + * + * @param string $objectType + * @param array $eventData + * @throws SystemException + */ + public function fireEvents($objectType, array $eventData) { + $objectTypeID = $this->getObjectTypeID($objectType); + if ($objectTypeID === null) { + throw new SystemException("Unknown recent activity event '".$objectType."'"); + } + + $itemsPerLoop = 1000; + $batchCount = ceil(count($eventData) / $itemsPerLoop); + + WCF::getDB()->beginTransaction(); + for ($i = 0; $i < $batchCount; $i++) { + $batchEventData = array_slice($eventData, $i * $itemsPerLoop, $itemsPerLoop); + + $parameters = []; + foreach ($batchEventData as $data) { + $parameters = array_merge($parameters, [ + $objectTypeID, + $data['objectID'], + $data['languageID'] ?? null, + $data['userID'] ?? WCF::getUser()->userID, + $data['time'] ?? TIME_NOW, + serialize($data['additionalData'] ?? []) + ]); + } + + $sql = "INSERT INTO wcf" . WCF_N . "_user_activity_event + (objectTypeID, objectID, languageID, userID, time, additionalData) + VALUES (?, ?, ?, ?, ?, ?)" . str_repeat(', (?, ?, ?, ?, ?, ?)', count($batchEventData) - 1); + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($parameters); + } + WCF::getDB()->commitTransaction(); + } + /** * Removes an activity event. *