fix: optimize queries and caching for projects and environments

This commit is contained in:
Andras Bacsai
2026-01-16 11:51:26 +01:00
parent 51301fd12e
commit 95091e918f
9 changed files with 203 additions and 35 deletions

View File

@@ -56,6 +56,28 @@ class SwarmDocker extends BaseModel
return $this->belongsTo(Server::class);
}
/**
* Get the server attribute using identity map caching.
* This intercepts lazy-loading to use cached Server lookups.
*/
public function getServerAttribute(): ?Server
{
// Use eager loaded data if available
if ($this->relationLoaded('server')) {
return $this->getRelation('server');
}
// Use identity map for lazy loading
$server = Server::findCached($this->server_id);
// Cache in relation for future access on this instance
if ($server) {
$this->setRelation('server', $server);
}
return $server;
}
public function services()
{
return $this->morphMany(Service::class, 'destination');