Mail bundling and processing performance improvements
This commit is contained in:
@@ -52,9 +52,10 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
protected Address $fftn_p; // Address the packet is from (when packing messages)
|
||||
protected Address $tftn_p; // Address the packet is to (when packing messages)
|
||||
protected Collection $messages; // Messages in the Packet
|
||||
protected string $content; // Outgoing packet data
|
||||
public Collection $errors; // Messages that fail validation
|
||||
protected int $index; // Our array index
|
||||
protected $pass_p = NULL; // Overwrite the packet password (when packing messages)
|
||||
protected $pass_p = NULL; // Overwrite the packet password (when packing messages)
|
||||
|
||||
/* ABSTRACT */
|
||||
|
||||
@@ -67,7 +68,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
* @return bool
|
||||
*/
|
||||
abstract public static function is_type(string $header): bool;
|
||||
abstract protected function header(): string;
|
||||
abstract protected function header(Collection $msgs): string;
|
||||
|
||||
/* STATIC */
|
||||
|
||||
@@ -287,20 +288,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
if (empty($this->messages))
|
||||
throw new InvalidPacketException('Refusing to make an empty packet');
|
||||
|
||||
if (empty($this->tftn_p) || empty($this->fftn_p))
|
||||
throw new InvalidPacketException('Cannot generate a packet without a destination address');
|
||||
|
||||
$return = $this->header();
|
||||
|
||||
foreach ($this->messages as $o)
|
||||
$return .= self::PACKED_MSG_LEAD.$o->packet($this->tftn_p);
|
||||
|
||||
$return .= "\00\00";
|
||||
|
||||
return $return;
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/* INTERFACE */
|
||||
@@ -360,7 +348,20 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
|
||||
public function mail(Collection $msgs): self
|
||||
{
|
||||
$this->messages = $msgs;
|
||||
if (! $msgs->count())
|
||||
throw new InvalidPacketException('Refusing to make an empty packet');
|
||||
|
||||
if (empty($this->tftn_p) || empty($this->fftn_p))
|
||||
throw new InvalidPacketException('Cannot generate a packet without a destination address');
|
||||
|
||||
$this->content = $this->header($msgs);
|
||||
|
||||
foreach ($msgs as $o)
|
||||
$this->content .= self::PACKED_MSG_LEAD.$o->packet($this->tftn_p);
|
||||
|
||||
$this->content .= "\00\00";
|
||||
|
||||
$this->messages = $msgs->map(fn($item)=>$item->only(['id','date']));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -381,7 +382,6 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
if ($msg->errors->count()) {
|
||||
Log::info(sprintf('%s:- Message [%s] has [%d] errors',self::LOGKEY,$msg->msgid ?: 'No ID',$msg->errors->count()));
|
||||
|
||||
|
||||
// If the messages is not for the right zone, we'll ignore it
|
||||
if ($msg->errors->has('invalid-zone')) {
|
||||
Log::alert(sprintf('%s:! Message [%s] is from an invalid zone [%s], packet is from [%s] - ignoring it',self::LOGKEY,$msg->msgid,$msg->fftn->zone->zone_id,$this->fftn->zone->zone_id));
|
||||
|
Reference in New Issue
Block a user