From 4db0702970318d6d8747d8833d5148d5d4332af1 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Fri, 4 Jul 2025 09:53:26 +0200 Subject: [PATCH] add caching & better error handling to update checking --- app/Models/Plugin.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index 5125cc48b..5ac2b59f4 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -4,6 +4,7 @@ namespace App\Models; use App\Contracts\Plugins\HasPluginSettings; use App\Enums\PluginStatus; +use Exception; use Filament\Forms\Components\Component; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\File; @@ -197,13 +198,19 @@ class Plugin extends Model implements HasPluginSettings return false; } - /** @var array */ - $updateData = file_get_contents($this->update_url); - if ($updateData[$panelVersion]) { - return version_compare($updateData[$panelVersion]['version'], $this->version, '>'); - } + return cache()->remember("plugins.$this->id.update", now()->addHour(), function () use ($panelVersion) { + try { + /** @var array */ + $updateData = file_get_contents($this->update_url); + if ($updateData[$panelVersion]) { + return version_compare($updateData[$panelVersion]['version'], $this->version, '>'); + } + } catch (Exception $exception) { + report($exception); + } - return false; + return false; + }); } public function hasSettings(): bool