parent
a3ba68ea98
commit
3b123d7f08
@ -0,0 +1,37 @@ |
||||
<?php |
||||
|
||||
|
||||
namespace App\Models\Concerns; |
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* Instance cache, used to avoid multiple retrieval of related models. |
||||
* Repeated calls to getCached() all return the same instance, without |
||||
* additional DB access. |
||||
*/ |
||||
trait InstanceCache |
||||
{ |
||||
private static $instanceCache = []; |
||||
|
||||
public static function bootInstanceCache() |
||||
{ |
||||
self::retrieved(function (Model $instance) { |
||||
self::$instanceCache[$instance->getKey()] = $instance; |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Find entity by ID, either in DB, or in the internal cache. |
||||
* |
||||
* @param int $id |
||||
* @return Model|null |
||||
*/ |
||||
public static function getCached($id) |
||||
{ |
||||
return isset(self::$instanceCache[$id]) ? |
||||
self::$instanceCache[$id] : |
||||
(self::$instanceCache[$id] = self::find($id)); |
||||
} |
||||
} |
@ -0,0 +1,29 @@ |
||||
<div class="list-group list-group-flush"> |
||||
@if(count($tables) == 0) |
||||
<span class="list-group-item">No tables yet.</span> |
||||
@else |
||||
@foreach($tables as $table) |
||||
<a class="list-group-item list-group-item-action" |
||||
href="{{route('table.view', ['user' => $table->cachedOwner()->name, 'table' => $table->name])}}"> |
||||
<span class="d-block row"> |
||||
<span class="d-inline-block col-10"> |
||||
<i class="fa-table fa-pr"></i>{{ $table->title }} |
||||
</span>{{-- |
||||
--}}<span class="d-inline-block col-2 small text-right"> |
||||
{{ $table->revision->row_count }} rows |
||||
</span> |
||||
</span> |
||||
|
||||
<span class="d-block small row"> |
||||
<span class="d-inline-block col-8"> |
||||
{{ ellipsis($table->description, 215) }} |
||||
</span>{{-- |
||||
--}}<span class="d-inline-block col-4 text-right text-muted"> |
||||
Last change {{ $table->updated_at->diffForHumans() }} |
||||
</span> |
||||
</span> |
||||
</a> |
||||
@endforeach |
||||
{{ $tables->links() }} |
||||
@endif |
||||
</div> |
Loading…
Reference in new issue