From 3e62e3d8e1389b9af7e30e3cc5208e8af8297ad7 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 26 Nov 2024 22:07:07 +1100 Subject: [PATCH] Batch up files when sending to a remote node --- app/Classes/File/Send.php | 2 +- app/Models/Address.php | 15 +++++++++++++++ app/Models/Setup.php | 4 ++++ app/Models/System.php | 15 ++++++++++----- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/Classes/File/Send.php b/app/Classes/File/Send.php index 8a8b608..ecc2da5 100644 --- a/app/Classes/File/Send.php +++ b/app/Classes/File/Send.php @@ -203,7 +203,7 @@ class Send extends Base } // Files - if (($x=$ao->filesWaiting())->count()) { + if (($x=$ao->getFiles())->count()) { Log::info(sprintf('%s:- [%d] Files(s) added for sending to [%s]',self::LOGKEY,$x->count(),$ao->ftn)); // Add Files diff --git a/app/Models/Address.php b/app/Models/Address.php index 52d11b4..27ba430 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -1187,6 +1187,21 @@ class Address extends Model return NULL; } + public function getFiles(): Collection + { + if ($count=($num=$this->filesWaiting())->count()) { + Log::info(sprintf('%s:= Got [%d] files for [%s] for sending',self::LOGKEY,$count,$this->ftn)); + + // Limit to max messages + if ($count > $this->system->batch_files) + Log::notice(sprintf('%s:= Only sending [%d] files for [%s]',self::LOGKEY,$this->system->batch_files,$this->ftn)); + + return $num->take($this->system->batch_files); + } + + return new Collection; + } + /** * Get netmail for this node (including it's children) * diff --git a/app/Models/Setup.php b/app/Models/Setup.php index 413438e..6343a0a 100644 --- a/app/Models/Setup.php +++ b/app/Models/Setup.php @@ -32,6 +32,7 @@ class Setup extends Model public const O_DNS = 1<<3; /* List for DNS */ public const O_HIDEAKA = 1<<4; /* Hide AKAs to different Zones */ + public const MAX_BATCH_FILES = 5; public const MAX_MSGS_PKT = 50; protected $casts = [ @@ -68,6 +69,9 @@ class Setup extends Model case 'emsi_options': return Arr::get($this->servers,str_replace('_','.',$key)); + case 'batch_files': + return Arr::get($this->options,$key,self::MAX_BATCH_FILES); + case 'msgs_pkt': return Arr::get($this->options,$key,self::MAX_MSGS_PKT); diff --git a/app/Models/System.php b/app/Models/System.php index 0ff1b92..aed5906 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -184,21 +184,26 @@ class System extends Model } } + public function getBatchFilesAttribute(?int $val): int + { + return $val ?: Setup::findOrFail(config('app.id'))->batch_files; + } + public function getIsOwnedAttribute(): bool { return $this->users->count(); } - public function getPktMsgsAttribute(?int $val): int - { - return $val ?: Setup::findOrFail(config('app.id'))->msgs_pkt; - } - public function getLastSeenAttribute(): ?Carbon { return $this->logs_recent->first()?->created_at; } + public function getPktMsgsAttribute(?int $val): int + { + return $val ?: Setup::findOrFail(config('app.id'))->msgs_pkt; + } + /* METHODS */ public function addresses_common(): Collection