mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 04:20:49 +08:00
improve hr + agent update
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ModelEventEnum;
|
||||
|
||||
class AgentAllow extends NexusModel
|
||||
{
|
||||
protected $table = 'agent_allowed_family';
|
||||
@@ -20,6 +22,19 @@ class AgentAllow extends NexusModel
|
||||
self::MATCH_TYPE_HEX => 'hex',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::created(function ($model) {
|
||||
fire_event(ModelEventEnum::AGENT_ALLOW_CREATED, $model);
|
||||
});
|
||||
static::updated(function ($model) {
|
||||
fire_event(ModelEventEnum::AGENT_ALLOW_UPDATED, $model);
|
||||
});
|
||||
static::deleted(function ($model) {
|
||||
fire_event(ModelEventEnum::AGENT_ALLOW_DELETED, $model);
|
||||
});
|
||||
}
|
||||
|
||||
public function denies(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(AgentDeny::class, 'family_id');
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ModelEventEnum;
|
||||
|
||||
class AgentDeny extends NexusModel
|
||||
{
|
||||
protected $table = 'agent_allowed_exception';
|
||||
@@ -10,6 +12,19 @@ class AgentDeny extends NexusModel
|
||||
'family_id', 'name', 'peer_id', 'agent', 'comment'
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::created(function ($model) {
|
||||
fire_event(ModelEventEnum::AGENT_DENY_CREATED, $model);
|
||||
});
|
||||
static::updated(function ($model) {
|
||||
fire_event(ModelEventEnum::AGENT_DENY_UPDATED, $model);
|
||||
});
|
||||
static::deleted(function ($model) {
|
||||
fire_event(ModelEventEnum::AGENT_DENY_DELETED, $model);
|
||||
});
|
||||
}
|
||||
|
||||
public function family(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(AgentAllow::class, 'family_id');
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ModelEventEnum;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\Exceptions\InvalidArgumentException;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class HitAndRun extends NexusModel
|
||||
{
|
||||
@@ -43,6 +44,31 @@ class HitAndRun extends NexusModel
|
||||
|
||||
const MINIMUM_IGNORE_USER_CLASS = User::CLASS_VIP;
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::saved(function ($model) {
|
||||
self::clearCache($model);
|
||||
});
|
||||
static::deleted(function ($model) {
|
||||
self::clearCache($model, ModelEventEnum::HIT_AND_RUN_DELETED);
|
||||
});
|
||||
}
|
||||
|
||||
public static function getCacheKey(int $userId, int $torrentId): string
|
||||
{
|
||||
return sprintf("hit_and_run:user:%d:torrent:%d", $userId, $torrentId);
|
||||
}
|
||||
|
||||
public static function clearCache(HitAndRun $hitAndRun, string $event = ModelEventEnum::HIT_AND_RUN_UPDATED): void
|
||||
{
|
||||
NexusDB::cache_del(self::getCacheKey($hitAndRun->uid, $hitAndRun->torrent_id));
|
||||
fire_event($event, $hitAndRun);
|
||||
do_log(sprintf(
|
||||
"userId: %s, torrentId: %s hit and run cache cleared, and trigger event: %s",
|
||||
$hitAndRun->uid, $hitAndRun->torrent_id, $event
|
||||
));
|
||||
}
|
||||
|
||||
protected function seedTimeRequired(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
|
||||
Reference in New Issue
Block a user