Fixes to message processing, now that we are using cockroachdb
This commit is contained in:
@@ -5,8 +5,8 @@ namespace App\Classes\FTN;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
||||
use App\Classes\FTN as FTNBase;
|
||||
@@ -59,8 +59,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
public Collection $messages; // Messages in the Packet
|
||||
public Collection $errors; // Messages that fail validation
|
||||
private string $name; // Packet name
|
||||
private ?System $system; // System the packet is from
|
||||
public bool $use_redis = TRUE; // Use redis for messages.
|
||||
public bool $use_cache = TRUE; // Use a cache for messages.
|
||||
private int $index; // Our array index
|
||||
|
||||
/**
|
||||
@@ -71,14 +70,14 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
return $this->messages->count();
|
||||
}
|
||||
|
||||
public function current()
|
||||
public function current(): Message
|
||||
{
|
||||
return $this->use_redis ? unserialize(Redis::get($this->key())) : $this->messages->get($this->index);
|
||||
return $this->use_cache ? unserialize(Cache::pull($this->key())) : $this->messages->get($this->index);
|
||||
}
|
||||
|
||||
public function key()
|
||||
public function key(): mixed
|
||||
{
|
||||
return $this->messages->get($this->index);
|
||||
return $this->use_cache ? $this->messages->get($this->index) : $this->index;
|
||||
}
|
||||
|
||||
public function next(): void
|
||||
@@ -86,14 +85,14 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
$this->index++;
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
public function rewind(): void
|
||||
{
|
||||
$this->index = 0;
|
||||
}
|
||||
|
||||
public function valid()
|
||||
public function valid(): bool
|
||||
{
|
||||
return $this->use_redis ? ($this->key() && Redis::exists($this->key())) : $this->key();
|
||||
return (! is_null($this->key())) && ($this->use_cache ? Cache::has($this->key()) : $this->messages->has($this->key()));
|
||||
}
|
||||
|
||||
public function __construct(Address $o=NULL)
|
||||
@@ -113,11 +112,11 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
*
|
||||
* @param File $file
|
||||
* @param System|null $system
|
||||
* @param bool $use_redis
|
||||
* @param bool $use_cache
|
||||
* @return Packet
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
public static function open(File $file,System $system=NULL,bool $use_redis=TRUE): self
|
||||
public static function open(File $file,System $system=NULL,bool $use_cache=TRUE): self
|
||||
{
|
||||
Log::debug(sprintf('%s:+ Opening Packet [%s]',self::LOGKEY,$file));
|
||||
|
||||
@@ -137,7 +136,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
throw new InvalidPacketException('Not a type 2 packet: '.$version);
|
||||
|
||||
$o = new self;
|
||||
$o->use_redis = $use_redis;
|
||||
$o->use_cache = $use_cache;
|
||||
$o->name = (string)$file;
|
||||
$o->header = unpack(self::unpackheader(self::v2header),$header);
|
||||
|
||||
@@ -428,7 +427,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
|
||||
// If the message is invalid, we'll ignore it
|
||||
if ($msg->errors) {
|
||||
Log::info(sprintf('%s:- Message has errors',self::LOGKEY));
|
||||
Log::info(sprintf('%s:- Message [%s] has errors',self::LOGKEY,$msg->msgid));
|
||||
|
||||
// If the from address doenst exist, we'll create a new entry
|
||||
if ($msg->errors->messages()->has('from')) {
|
||||
@@ -479,9 +478,9 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->use_redis) {
|
||||
$key = $msg->msgid ?: sprintf('%s %s',$msg->fftn,Carbon::now()->timestamp);
|
||||
Redis::set($key,serialize($msg));
|
||||
if ($this->use_cache) {
|
||||
$key = urlencode($msg->msgid ?: sprintf('%s %s',$msg->fftn,Carbon::now()->timestamp));
|
||||
Cache::forever($key,serialize($msg));
|
||||
$this->messages->push($key);
|
||||
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user