Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: Prevent N+1 query in LocalPersistentVolume.isDockerComposeResource()

Andras Bacsai475cfd78cd19
diff --git a/app/Livewire/Project/Service/Storage.php b/app/Livewire/Project/Service/Storage.php
index 644b100b8c..12d8bcbc32 100644
--- a/app/Livewire/Project/Service/Storage.php
+++ b/app/Livewire/Project/Service/Storage.php
@@ -67,7 +67,7 @@ class Storage extends Component
public function refreshStorages()
{
$this->fileStorage = $this->resource->fileStorages()->get();
- $this->resource->refresh();
+ $this->resource->load('persistentStorages.resource');
}
public function getFilesProperty()
diff --git a/app/Models/LocalPersistentVolume.php b/app/Models/LocalPersistentVolume.php
index 26e9b3e857..7126253eaa 100644
--- a/app/Models/LocalPersistentVolume.php
+++ b/app/Models/LocalPersistentVolume.php
@@ -10,6 +10,11 @@ class LocalPersistentVolume extends Model
{
protected $guarded = [];
+ public function resource()
+ {
+ return $this->morphTo('resource');
+ }
+
public function application()
{
return $this->morphTo('resource');
@@ -50,6 +55,54 @@ class LocalPersistentVolume extends Model
);
}
+ // Check if this volume belongs to a service resource
+ public function isServiceResource(): bool
+ {
+ return in_array($this->resource_type, [
+ 'App\Models\ServiceApplication',
+ 'App\Models\ServiceDatabase',
+ ]);
+ }
+
+ // Check if this volume belongs to a dockercompose application
+ public function isDockerComposeResource(): bool
+ {
+ if ($this->resource_type !== 'App\Models\Application') {
+ return false;
+ }
+
+ // Only access relationship if already eager loaded to avoid N+1
+ if (! $this->relationLoaded('resource')) {
+ return false;
+ }
+
+ $application = $this->resource;
+ if (! $application) {
+ return false;
+ }
+
+ return data_get($application, 'build_pack') === 'dockercompose';
+ }
+
+ // Determine if this volume should be read-only in the UI
+ // Service volumes and dockercompose application volumes are read-only
+ // (users should edit compose file directly)
+ public function shouldBeReadOnlyInUI(): bool
+ {
+ // All service volumes should be read-only in UI
+ if ($this->isServiceResource()) {
+ return true;
+ }
+
+ // All dockercompose application volumes should be read-only in UI
+ if ($this->isDockerComposeResource()) {
+ return true;
+ }
+
+ // Check for explicit :ro flag in compose (existing logic)
+ return $this->isReadOnlyVolume();
+ }
+
// Check if this volume is read-only by parsing the docker-compose content
public function isReadOnlyVolume(): bool
{