Improved performance for file logging
authorAlexander Ebert <ebert@woltlab.com>
Mon, 20 May 2013 22:55:02 +0000 (00:55 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 20 May 2013 22:55:02 +0000 (00:55 +0200)
wcfsetup/install/files/lib/system/package/FilesFileHandler.class.php

index fda4ac8dcbf34cd7a893fe2f1fdedb634692e887..5e5be6be0b7c7a54d4f021d91749999e0095209b 100644 (file)
@@ -61,39 +61,14 @@ class FilesFileHandler extends PackageInstallationFileHandler {
                        return;
                }
                
-               // fetch already installed files
-               $conditions = new PreparedStatementConditionBuilder();
-               $conditions->add('packageID = ?', array($this->packageInstallation->getPackageID()));
-               $conditions->add('filename IN (?)', array($files));
-               $conditions->add('application = ?', array($this->application));
-               
-               $sql = "SELECT  filename
-                       FROM    wcf".WCF_N."_package_installation_file_log
-                       ".$conditions;
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute($conditions->getParameters());
-               
-               while ($filename = $statement->fetchColumn()) {
-                       $index = array_search($filename, $files);
-                       
-                       if ($index !== false) {
-                               unset($files[$index]);
-                       }
-               }
-               
-               if (!empty($files)) {
-                       $sql = "INSERT INTO     wcf".WCF_N."_package_installation_file_log
-                                               (packageID, filename, application)
-                               VALUES          (?, ?, ?)";
+               // insert 50 files per loop
+               for ($i = 0, $steps = ceil(count($files) / 50); $i < $steps; $i++) {
+                       $items = array_slice($files, 0, 50);
+                       $sql = "INSERT IGNORE INTO      wcf".WCF_N."_package_installation_file_log
+                                                       (packageID, filename, application)
+                               VALUES                  ".substr(str_repeat("(".$this->packageInstallation->getPackageID().", ?, '".$this->application."'), ", count($items)), 0, -2);
                        $statement = WCF::getDB()->prepareStatement($sql);
-                       
-                       foreach ($files as $file) {
-                               $statement->execute(array(
-                                       $this->packageInstallation->getPackageID(),
-                                       $file,
-                                       $this->application
-                               ));
-                       }
+                       $statement->execute($items);
                }
        }
 }