refactor: replace queries with cached versions for performance improvements

This commit is contained in:
Andras Bacsai
2025-12-08 13:39:33 +01:00
parent bb83f4e5c3
commit 5e8d11f732
28 changed files with 305 additions and 125 deletions

View File

@@ -30,11 +30,25 @@ class Project extends BaseModel
protected $guarded = [];
/**
* Get query builder for projects owned by current team.
* If you need all projects without further query chaining, use ownedByCurrentTeamCached() instead.
*/
public static function ownedByCurrentTeam()
{
return Project::whereTeamId(currentTeam()->id)->orderByRaw('LOWER(name)');
}
/**
* Get all projects owned by current team (cached for request duration).
*/
public static function ownedByCurrentTeamCached()
{
return once(function () {
return Project::ownedByCurrentTeam()->get();
});
}
protected static function booted()
{
static::created(function ($project) {