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.
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
+ '',
]);
}
}