mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 18:20:48 +01:00
feat(controllers): optimize caching and view data passing
- Refactored the ChampionController, ChampionSkinController, HomeController, SaleController, SummonerEmoteController, and SummonerIconController to use arrow functions for cache callbacks. - Updated the view data passing in the ChampionController, ChampionSkinController, HomeController, PostsController, SaleController, SummonerEmoteController, and SummonerIconController to use associative arrays instead of compact(). - Removed unused imports from web.php.
This commit is contained in:
@@ -17,15 +17,11 @@ class ChampionController extends Controller
|
||||
{
|
||||
$eightHoursInSeconds = 60 * 60 * 8;
|
||||
|
||||
$champions = Cache::remember('championsListAllCache', $eightHoursInSeconds, function () {
|
||||
return Champion::orderBy('name')->get();
|
||||
});
|
||||
$champions = Cache::remember('championsListAllCache', $eightHoursInSeconds, static fn() => Champion::orderBy('name')->get());
|
||||
|
||||
$roles = Cache::remember('championsRolesCache', $eightHoursInSeconds, function () {
|
||||
return ChampionRoles::orderBy('champion_name')->get();
|
||||
});
|
||||
$roles = Cache::remember('championsRolesCache', $eightHoursInSeconds, static fn() => ChampionRoles::orderBy('champion_name')->get());
|
||||
|
||||
return view('champions.index', compact('champions', 'roles'));
|
||||
return view('champions.index', ['champions' => $champions, 'roles' => $roles]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,21 +48,17 @@ class ChampionController extends Controller
|
||||
$eightHoursInSeconds = 60 * 60 * 8;
|
||||
$dayInSeconds = 60 * 60 * 24;
|
||||
|
||||
$champion = Cache::remember('championShowCache' . $champion->slug, $eightHoursInSeconds, function () use ($champion) {
|
||||
return $champion->load('skins', 'lanes');
|
||||
});
|
||||
$champion = Cache::remember('championShowCache' . $champion->slug, $eightHoursInSeconds, static fn() => $champion->load('skins', 'lanes'));
|
||||
|
||||
$splashColor = Cache::remember(
|
||||
'championSplashColorCache' . $champion->slug,
|
||||
$dayInSeconds,
|
||||
function () use ($champion) {
|
||||
return getAverageColorFromImageUrl($champion->getChampionImageAttribute());
|
||||
}
|
||||
static fn() => getAverageColorFromImageUrl($champion->getChampionImageAttribute())
|
||||
);
|
||||
|
||||
$champion->splash_color = $splashColor;
|
||||
|
||||
return view('champions.show', compact('champion'));
|
||||
return view('champions.show', ['champion' => $champion]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,7 +30,7 @@ class ChampionSkinController extends Controller
|
||||
'Ultimate' => 'text-yellow-400',
|
||||
];
|
||||
|
||||
return view('skins.index', compact('skins', 'rarityColor'));
|
||||
return view('skins.index', ['skins' => $skins, 'rarityColor' => $rarityColor]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,22 +57,18 @@ class ChampionSkinController extends Controller
|
||||
$skin = Cache::remember(
|
||||
'championSkinShowCache' . $championSkin->slug,
|
||||
60 * 60 * 8,
|
||||
function () use ($championSkin) {
|
||||
return $championSkin->load('champion', 'chromas');
|
||||
}
|
||||
static fn() => $championSkin->load('champion', 'chromas')
|
||||
);
|
||||
|
||||
$splashColor = Cache::remember(
|
||||
'championSkinSplashColorCache' . $championSkin->slug,
|
||||
60 * 60 * 24,
|
||||
function () use ($championSkin) {
|
||||
return getAverageColorFromImageUrl($championSkin->getSkinImageAttribute());
|
||||
}
|
||||
static fn() => getAverageColorFromImageUrl($championSkin->getSkinImageAttribute())
|
||||
);
|
||||
|
||||
$skin->splash_color = $splashColor;
|
||||
|
||||
return view('skins.show', compact('skin'));
|
||||
return view('skins.show', ['skin' => $skin]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,15 +9,11 @@ class HomeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$upcomingSkins = Cache::remember('upcomingSkins_home', 60 * 4, function () {
|
||||
return ChampionSkin::where('availability', 'Upcoming')
|
||||
->orderBy('release_date', 'desc')->get();
|
||||
});
|
||||
$upcomingSkins = Cache::remember('upcomingSkins_home', 60 * 4, static fn() => ChampionSkin::where('availability', 'Upcoming')
|
||||
->orderBy('release_date', 'desc')->get());
|
||||
|
||||
$latestSkins = Cache::remember('latestSkins_home', 60 * 4, function () {
|
||||
return ChampionSkin::where('availability', 'Available')
|
||||
->orderBy('release_date', 'desc')->take(9)->get();
|
||||
});
|
||||
$latestSkins = Cache::remember('latestSkins_home', 60 * 4, static fn() => ChampionSkin::where('availability', 'Available')
|
||||
->orderBy('release_date', 'desc')->take(9)->get());
|
||||
|
||||
return view('home', [
|
||||
'latestSkins' => $latestSkins,
|
||||
|
||||
@@ -20,6 +20,6 @@ class PostsController extends Controller
|
||||
|
||||
public function show(Sheet $post)
|
||||
{
|
||||
return view('posts.show', compact('post'));
|
||||
return view('posts.show', ['post' => $post]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,15 @@ class SaleController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$sales = Cache::remember('sales_data', 60 * 60 * 8, function () {
|
||||
$sales = Cache::remember('sales_data', 60 * 60 * 8, static function () {
|
||||
$shopData = json_decode(
|
||||
file_get_contents('https://api.shop.riotgames.com/v3/collections/'),
|
||||
true
|
||||
);
|
||||
$salesData = array_filter($shopData, function ($collection) {
|
||||
return $collection['path'] === '/event/sales';
|
||||
});
|
||||
$salesData = array_filter($shopData, static fn($collection) => $collection['path'] === '/event/sales');
|
||||
return reset($salesData)['dynamicCollection']['discountedProductsByProductType'] ?? [];
|
||||
});
|
||||
|
||||
return view('sales.index', compact('sales'));
|
||||
return view('sales.index', ['sales' => $sales]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class SummonerEmoteController extends Controller
|
||||
->paginate(72)
|
||||
->appends(request()->query());
|
||||
|
||||
return view('emotes.index', compact('emotes'));
|
||||
return view('emotes.index', ['emotes' => $emotes]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
|
||||
@@ -16,7 +16,7 @@ class SummonerIconController extends Controller
|
||||
->paginate(72)
|
||||
->appends(request()->query());
|
||||
|
||||
return view('icons.index', compact('icons'));
|
||||
return view('icons.index', ['icons' => $icons]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
@@ -40,7 +40,7 @@ class SummonerIconController extends Controller
|
||||
{
|
||||
$icon = $summonerIcon;
|
||||
|
||||
return view('icons.show', compact('icon'));
|
||||
return view('icons.show', ['icon' => $icon]);
|
||||
}
|
||||
|
||||
public function update(Request $request, SummonerIcon $summonerIcon)
|
||||
|
||||
Reference in New Issue
Block a user