Skip to content

Commit

Permalink
Replace nested trees with common table expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
ilestis committed Dec 2, 2023
1 parent 719f1f5 commit f1fb16f
Show file tree
Hide file tree
Showing 49 changed files with 287 additions and 1,697 deletions.
78 changes: 0 additions & 78 deletions app/Console/Commands/GenerateTrees.php

This file was deleted.

2 changes: 1 addition & 1 deletion app/Http/Controllers/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function crudIndex(Request $request)
$parent = null;
if (request()->has('parent_id')) {
// @phpstan-ignore-next-line
$parentKey = $model->getParentIdName();
$parentKey = $model->getParentKeyName();
$base->where([$model->getTable() . '.' . $parentKey => request()->get('parent_id')]);

$parent = $model->where('id', request()->get('parent_id'))->first();
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Locations/CharacterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function index(Campaign $campaign, Location $location)
'location', 'location.entity',
'races', 'families',
])
->filter($filters)
->filteredCharacters()
->paginate();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Locations/LocationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function index(Campaign $campaign, Location $location)
// @phpstan-ignore-next-line
$this->rows = $location
->descendants()
->select(['id', 'image', 'name', 'type', 'location_id', 'is_private'])
->select(['id', 'name', 'type', 'location_id', 'is_private'])
->sort(request()->only(['o', 'k']), ['name' => 'asc'])
->filter($filters)
->with([
Expand Down
17 changes: 4 additions & 13 deletions app/Models/Ability.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Arr;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;

/**
* Class Ability
Expand All @@ -34,10 +35,9 @@ class Ability extends MiscModel
use CampaignTrait;
use ExportableTrait;
use HasFactory;
use Nested;
use HasRecursiveRelationships;
use SoftDeletes;
use SortableTrait
;
use SortableTrait;

/** @var string[] */
protected $fillable = [
Expand Down Expand Up @@ -86,20 +86,11 @@ class Ability extends MiscModel
* Parent ID used for the Node Trait
* @return string
*/
public function getParentIdName()
public function getParentKeyName()
{
return 'ability_id';
}

/**
* Specify parent id attribute mutator
* @param int $value
*/
public function setAbilityIdAttribute($value)
{
$this->setParentIdAttribute($value);
}

/**
* Performance with for datagrids
*/
Expand Down
14 changes: 3 additions & 11 deletions app/Models/AttributeTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Traits\CampaignTrait;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;

/**
* Class AttributeTemplate
Expand All @@ -23,7 +24,7 @@ class AttributeTemplate extends MiscModel
{
use Acl;
use CampaignTrait;
use Nested;
use HasRecursiveRelationships;
use SoftDeletes;

/**
Expand Down Expand Up @@ -96,20 +97,11 @@ public function attributeTemplates()
* Parent ID field for the Node trait
* @return string
*/
public function getParentIdName()
public function getParentKeyName()
{
return 'attribute_template_id';
}

/**
* Specify parent id attribute mutator
* @param int $value
*/
public function setAttributeTemplateIdAttribute($value)
{
$this->setParentIdAttribute($value);
}

/**
* Performance with for datagrids
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function datagridSelectFields(): array
return ['calendar_id', 'date'];
}

public function getParentIdName(): string
public function getParentKeyName(): string
{
return 'calendar_id';
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Concerns/HasFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,6 @@ protected function getFilterOption(): FilterOption

protected function filterParent(Builder $query): void
{
$query->where($this->getTable() . '.' . $this->getParentIdName(), $this->filterValue);
$query->where($this->getTable() . '.' . $this->getParentKeyName(), $this->filterValue);
}
}
Loading

0 comments on commit f1fb16f

Please sign in to comment.