Run cleanup queries during maintenance in download.php
The download.php
script contains a maintenance routine that runs infrequently. As part of this routine, we should include additional cleanup queries to help keep the download_file_index table small and performant. Specifically, we should execute the following SQL statements during the maintenance phase:
DELETE FROM download_file_index WHERE file_name NOT LIKE '/stat%' AND download_count = 0;
DELETE FROM download_file_index WHERE file_name NOT LIKE '/stat%' AND timestamp_disk = 0;
These queries will remove stale or unused entries that are not related to /stat% paths and have either never been downloaded or have no associated disk timestamp. Keeping this table small ensures that even under high load—hundreds of queries per second—the lookup performance remains optimal.