feat: caching

This commit is contained in:
Rico van Zelst
2023-11-06 21:47:51 +01:00
parent 3d6c00dd0d
commit 90e36c74ec
5 changed files with 39 additions and 32 deletions

View File

@@ -3,15 +3,23 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\ChampionSkin; use App\Models\ChampionSkin;
use Illuminate\Support\Facades\Cache;
class HomeController extends Controller class HomeController extends Controller
{ {
public function index() public function index()
{ {
$skins = ChampionSkin::orderBy('release_date', 'desc')->get(); $skins = Cache::remember('skins', 60 * 4, function () {
return ChampionSkin::orderBy('release_date', 'desc')->get();
});
$upcomingSkins = Cache::remember('upcomingSkins', 60 * 4, function () use ($skins) {
return $skins->where('availability', 'Upcoming');
});
return view('home', [ return view('home', [
'skins' => $skins, 'skins' => $skins,
'upcomingSkins' => $upcomingSkins,
]); ]);
} }
} }

View File

@@ -5,9 +5,9 @@ namespace App\View\Components\Home;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\View\Component; use Illuminate\View\Component;
class Upcoming_skins extends Component class upcoming_skins extends Component
{ {
public function __construct(public array $skins) public function __construct(public array $upcomingSkins)
{ {
} }

View File

@@ -5,6 +5,7 @@ namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents; // use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Cache;
class DatabaseSeeder extends Seeder class DatabaseSeeder extends Seeder
{ {
@@ -18,6 +19,8 @@ class DatabaseSeeder extends Seeder
$this->call(SkinChromaSeeder::class); $this->call(SkinChromaSeeder::class);
$this->call(ChampionRolesSeeder::class); $this->call(ChampionRolesSeeder::class);
Cache::flush();
Log::info('Seeding complete at ' . date('Y-m-d H:i:s')); Log::info('Seeding complete at ' . date('Y-m-d H:i:s'));
} }
} }

View File

@@ -15,39 +15,33 @@
</p> </p>
</div> </div>
<div class="grid grid-cols-1 gap-4 mt-8 md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-3"> <div class="grid grid-cols-1 gap-4 mt-8 md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-3">
@foreach ($skins as $skin) @foreach ($upcomingSkins as $skin)
@if($skin->availability == "Upcoming") <div
<div class="p-8 transition border shadow-xl border-stone-800 rounded-xl hover:border-orange-500/10 hover:shadow-orange-500/10">
class="p-8 transition border shadow-xl border-stone-800 rounded-xl hover:border-orange-500/10 hover:shadow-orange-500/10"> <div class="flex flex-col">
<div class="flex flex-col"> <div class="flex flex-col items-center justify-center">
<img loading="lazy" class="border-2 border-orange-400/40 rounded-xl"
src="{{ $skin->getSkinImageAttribute(true) }}"
alt="{{ $skin->skin_name }} Splash Art">
<div class="flex flex-col items-center justify-center"> <div class="flex flex-col items-center justify-center">
<img loading="lazy" class="border-2 border-orange-400/40 rounded-xl" <h2 class="mt-4 text-xl font-bold text-white">{{ $skin->skin_name }}</h2>
src="{{ $skin->getSkinImageAttribute(true) }}" <p class="mt-1 text-sm text-stone-300">
alt="{{ $skin->skin_name }} Splash Art"> @if ($skin->rp_price == '99999')
<div class="flex flex-col items-center justify-center"> Not Available for RP
<h2 class="mt-4 text-xl font-bold text-white">{{ $skin->skin_name }}</h2> @else
<p class="mt-1 text-sm text-stone-300"> {{ $skin->rp_price }} RP
@if ($skin->rp_price == '99999') @endif
Not Available for RP </p>
@else <p class="mt-1 text-sm italic text-stone-300">
{{ $skin->rp_price }} RP @if ($skin->loot_eligible)
@endif Can be obtained from loot
@endif
</p> </p>
<p class="mt-1 text-sm italic text-stone-300">
@if ($skin->loot_eligible)
Can be obtained from loot
@endif
</p>
</div>
</div> </div>
</div> </div>
</div> </div>
@endif </div>
@endforeach @endforeach
</div> </div>
</div> </div>
</section> </section>

View File

@@ -30,7 +30,9 @@
<body class="antialiased bg-stone-800 dark"> <body class="antialiased bg-stone-800 dark">
<x-navbar/> <x-navbar/>
<x-home.features/> <x-home.features/>
<x-home.upcoming_skins :skins="$skins"/> @if($upcomingSkins != [])
<x-home.upcoming_skins :upcomingSkins="$upcomingSkins"/>
@endif
<x-home.recent_skins :skins="$skins"/> <x-home.recent_skins :skins="$skins"/>
</body> </body>