From: Matthias Schmidt Date: Sat, 22 Jun 2019 12:10:04 +0000 (+0200) Subject: Delete search index entries in batches X-Git-Tag: 5.2.0_Alpha_3~26^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f741c985f6ae86df6f49ae6981bde77ddba09644;p=GitHub%2FWoltLab%2FWCF.git Delete search index entries in batches --- diff --git a/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchIndexManager.class.php b/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchIndexManager.class.php index 52fa1d485a..b160a89c42 100644 --- a/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchIndexManager.class.php +++ b/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchIndexManager.class.php @@ -44,12 +44,20 @@ class MysqlSearchIndexManager extends AbstractSearchIndexManager { * @inheritDoc */ public function delete($objectType, array $objectIDs) { - $sql = "DELETE FROM " . SearchIndexManager::getTableName($objectType) . " - WHERE objectID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); + // instead of executing one query per object id, execute queries + // for batches of up to 1000 object ids at once + $itemsPerLoop = 1000; + $batchCount = ceil(count($objectIDs) / $itemsPerLoop); + $tableName = SearchIndexManager::getTableName($objectType); + WCF::getDB()->beginTransaction(); - foreach ($objectIDs as $objectID) { - $statement->execute([$objectID]); + for ($i = 0; $i < $batchCount; $i++) { + $batchObjectIDs = array_slice($objectIDs, $i * $itemsPerLoop, $itemsPerLoop); + + $sql = "DELETE FROM " . $tableName . " + WHERE objectID IN (?" . str_repeat(', ?', count($batchObjectIDs) - 1) . ")"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($batchObjectIDs); } WCF::getDB()->commitTransaction(); }