In smart_delete_backups(), there is a while loop that could be made more efficient with some simple math:
// Increment time till we get within one period time span of the period
// start time. This keeps all the different period starts aligned.
while ($time < $period_start_time) {
$time += $period['delta'];
}
Rather than adding in a while loop, you can subtract the values in the condition and divide by delta to see exactly how many times the delta will be added, then multiply by the delta and add it all at once. This gives the same result, but is noticeably faster:
if ($time < $period_start_time) {
$time += ((int) ceil(($period_start_time - $time) / $period['delta'])) * $period['delta'];
}
Depending on how old the $oldest_file_time is, this can easily shave an entire second off the execution time.
Comments
Comment #2
solideogloria commentedComment #3
solideogloria commentedGo here for a quick PHP runtime comparison in an online interpreter (TIO - Try It Online)
Comment #4
damienmckennaThat's some good sleuthing, thank you!
Comment #5
brankoc commentedThe preceding comment in the code makes slightly less sense in the patched version (mainly because of the 'till', which suggests a process to me).
How about?
Comment #6
solideogloria commentedSounds good to me. Updated patch.
Comment #8
damienmckennaCommitted. Thank you.