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

solideogloria created an issue. See original summary.

solideogloria’s picture

Status: Active » Needs review
StatusFileSize
new676 bytes
damienmckenna’s picture

That's some good sleuthing, thank you!

brankoc’s picture

The 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?

      // Increase time to within one period time span of the period start 
      // time. This keeps all the different period starts aligned.
solideogloria’s picture

StatusFileSize
new953 bytes

Sounds good to me. Updated patch.

damienmckenna’s picture

Status: Needs review » Fixed
Parent issue: » #3020775: Plan for Backup and Migrate 7.x-3.7

Committed. Thank you.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.