mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 18:20:48 +01:00
fix: query optimization
⚡ 166 Queries -> 2 Queries (cached)
This commit is contained in:
14
app/Helpers/HelperFunctions.php
Normal file
14
app/Helpers/HelperFunctions.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
function getRoleIcon($roleName)
|
||||
{
|
||||
$roleIcons = [
|
||||
'Toplane' => 'gm-top.png',
|
||||
'Jungle' => 'gm-jungle.png',
|
||||
'Midlane' => 'gm-mid.png',
|
||||
'Botlane' => 'gm-bot.png',
|
||||
'Support' => 'gm-support.png',
|
||||
];
|
||||
|
||||
return asset('img/' . $roleIcons[$roleName]);
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace App\Http\Controllers;
|
||||
use App\Http\Requests\StoreChampionRequest;
|
||||
use App\Http\Requests\UpdateChampionRequest;
|
||||
use App\Models\Champion;
|
||||
use App\Models\ChampionRoles;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ChampionController extends Controller
|
||||
{
|
||||
@@ -13,9 +15,15 @@ class ChampionController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$champions = Champion::orderBy('name')->get();
|
||||
$champions = Cache::remember('championsListAllCache', 60 * 60 * 8, function () {
|
||||
return Champion::orderBy('name')->get();
|
||||
});
|
||||
|
||||
return view('champions.index', compact('champions'));
|
||||
$roles = Cache::remember('championsRolesCache', 60 * 60 * 8, function () {
|
||||
return ChampionRoles::orderBy('champion_name')->get();
|
||||
});
|
||||
|
||||
return view('champions.index', compact('champions', 'roles'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,17 +47,4 @@ class ChampionRoles extends Model
|
||||
|
||||
return $transformedRoles;
|
||||
}
|
||||
|
||||
public function getRoleIcon($roleName)
|
||||
{
|
||||
$roleIcons = [
|
||||
'Toplane' => 'gm-top.png',
|
||||
'Jungle' => 'gm-jungle.png',
|
||||
'Midlane' => 'gm-mid.png',
|
||||
'Botlane' => 'gm-bot.png',
|
||||
'Support' => 'gm-support.png',
|
||||
];
|
||||
|
||||
return asset('img/' . $roleIcons[$roleName]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use Illuminate\View\Component;
|
||||
|
||||
class List_all extends Component
|
||||
{
|
||||
public function __construct(public array $champions)
|
||||
public function __construct(public array $champions, public array $roles)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
"name": "laravel/laravel",
|
||||
"type": "project",
|
||||
"description": "The skeleton application for the Laravel framework.",
|
||||
"keywords": ["laravel", "framework"],
|
||||
"keywords": [
|
||||
"laravel",
|
||||
"framework"
|
||||
],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
@@ -33,7 +36,10 @@
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"app/Helpers/HelperFunctions.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
<body class="antialiased bg-stone-900 dark">
|
||||
<x-navbar/>
|
||||
<x-champions.list_all :champions="$champions"/>
|
||||
<x-champions.list_all :champions="$champions" :roles="$roles"/>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
/** @var App\Models\Champion $champion */
|
||||
|
||||
/** @var App\Models\ChampionRoles $lanes */ ?>
|
||||
/** @var App\Models\ChampionRole $roles */
|
||||
?>
|
||||
|
||||
|
||||
<section class="max-w-screen-xl mx-auto mt-12">
|
||||
@@ -36,13 +37,13 @@
|
||||
|
||||
<div class="flex items-center justify-between mt-2">
|
||||
<p class="text-gray-300 text-sm flex">
|
||||
@foreach($champion->lanes->roles as $lane)
|
||||
@foreach($roles[$key]->roles as $lane)
|
||||
<span class="sr-only">{{$lane}}</span>
|
||||
|
||||
<img data-tooltip-target="tooltip-bottom-{{$lane}}"
|
||||
data-tooltip-placement="bottom"
|
||||
@if($key < 8) loading="auto" @else loading="lazy"
|
||||
@endif src="{{$champion->lanes->getRoleIcon($lane)}}"
|
||||
@endif src="{{getRoleIcon($lane)}}"
|
||||
alt="{{$lane}} Icon"
|
||||
class="w-7 h-7 mr-1">
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user