diff --git a/backup/util/dbops/backup_controller_dbops.class.php b/backup/util/dbops/backup_controller_dbops.class.php index 668ff6147c0..409be32acad 100644 --- a/backup/util/dbops/backup_controller_dbops.class.php +++ b/backup/util/dbops/backup_controller_dbops.class.php @@ -32,6 +32,16 @@ */ abstract class backup_controller_dbops extends backup_dbops { + /** + * @var string Backup id for cached backup_includes_files result. + */ + protected static $includesfilescachebackupid; + + /** + * @var int Cached backup_includes_files result + */ + protected static $includesfilescache; + /** * Send one backup controller to DB * @@ -441,9 +451,20 @@ abstract class backup_controller_dbops extends backup_dbops { * @return int Indicates whether files should be included in backups. */ public static function backup_includes_files($backupid) { - // Load controller + // This function is called repeatedly in a backup with many files. + // Loading the controller is a nontrivial operation (in a large test + // backup it took 0.3 seconds), so we do a temporary cache of it within + // this request. + if (self::$includesfilescachebackupid === $backupid) { + return self::$includesfilescache; + } + + // Load controller, get value, then destroy controller and return result. + self::$includesfilescachebackupid = $backupid; $bc = self::load_controller($backupid); - return $bc->get_include_files(); + self::$includesfilescache = $bc->get_include_files(); + $bc->destroy(); + return self::$includesfilescache; } /**