No need for function

This commit is contained in:
Lance Pioch 2024-03-17 14:27:24 -04:00
parent 0dacfc31ac
commit a3f33eea3f
2 changed files with 7 additions and 14 deletions

View File

@ -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();
}
}

View File

@ -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);