Optimized IP Address Pruning Process
authorSascha Greuel <github@1-2.dev>
Sun, 25 Feb 2024 16:05:33 +0000 (17:05 +0100)
committerSascha Greuel <github@1-2.dev>
Sun, 25 Feb 2024 16:05:33 +0000 (17:05 +0100)
Currently, when pruning IP addresses, each row within the database tables is examined, including those that have already been processed. This approach can significantly slow down queries in large communities. To enhance efficiency, it is proposed that rows with already processed (empty) IP addresses be excluded from further processing.

This PR optimizes the IP address pruning process by excluding rows where the IP address has already been cleared, thereby reducing unnecessary database query processing.

wcfsetup/install/files/lib/system/cronjob/PruneIpAddressesCronjob.class.php

index 54cfb2ed916bb5b814038d27beb1bf7e7fb87315..66028fd938c9082e6dc272d677efafe44850922b 100644 (file)
@@ -43,11 +43,13 @@ class PruneIpAddressesCronjob extends AbstractCronjob
             foreach ($columnData as $ipAddressColumn => $timestampColumn) {
                 $sql = "UPDATE  {$tableName}
                         SET     {$ipAddressColumn} = ?
-                        WHERE   {$timestampColumn} <= ?";
+                        WHERE   {$timestampColumn} <= ?
+                            AND {$ipAddressColumn} <> ?";
                 $statement = WCF::getDB()->prepareStatement($sql);
                 $statement->execute([
                     '',
                     TIME_NOW - 86400 * PRUNE_IP_ADDRESS, // 86400 = 1 day
+                    '',
                 ]);
             }
         }