diff --git a/app/Models/Server.php b/app/Models/Server.php index 7a56eb39a..d921a101a 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -387,17 +387,4 @@ class Server extends Model throw new DaemonConnectionException($exception); } } - - /** - * Determines if too many backups have been generated by the server. - */ - public function getBackupsGeneratedDuringTimespan(int $seconds = 600): array|Collection - { - return $this - ->backups() - ->where(fn ($query) => $query->whereNull('completed_at')->orWhere('is_successful', true)) - ->where('created_at', '>=', now()->subSeconds($seconds)) - ->withTrashed() - ->get(); - } } diff --git a/app/Services/Backups/InitiateBackupService.php b/app/Services/Backups/InitiateBackupService.php index 908979ff3..0b89a3a9b 100644 --- a/app/Services/Backups/InitiateBackupService.php +++ b/app/Services/Backups/InitiateBackupService.php @@ -76,7 +76,13 @@ class InitiateBackupService $limit = config('backups.throttles.limit'); $period = config('backups.throttles.period'); if ($period > 0) { - $previous = $server->getBackupsGeneratedDuringTimespan($period); + $previous = $server + ->backups() + ->where('created_at', '>=', now()->subSeconds($period)) + ->nonFailed() + ->withTrashed() + ->get(); + if ($previous->count() >= $limit) { $message = sprintf('Only %d backups may be generated within a %d second span of time.', $limit, $period);