Better throttling of backup generation

This commit is contained in:
Dane Everitt 2020-04-09 22:35:38 -07:00
parent 63d8cd4f3f
commit 06707fd33a
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 43 additions and 3 deletions

View file

@ -2,6 +2,7 @@
namespace Pterodactyl\Repositories\Eloquent;
use Carbon\Carbon;
use Pterodactyl\Models\Backup;
class BackupRepository extends EloquentRepository
@ -13,4 +14,21 @@ class BackupRepository extends EloquentRepository
{
return Backup::class;
}
/**
* Determines if too many backups have been generated by the server.
*
* @param int $server
* @param int $minutes
* @return \Pterodactyl\Models\Backup[]|\Illuminate\Support\Collection
*/
public function getBackupsGeneratedDuringTimespan(int $server, int $minutes = 10)
{
return $this->getBuilder()
->withTrashed()
->where('server_id', $server)
->where('created_at', '>=', Carbon::now()->subMinutes($minutes)->toDateTimeString())
->get()
->toBase();
}
}