Use redirect for random button to save database queries
This commit is contained in:
@@ -52,6 +52,22 @@ class HomeController extends Controller
|
||||
return view('auth.banned');
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects to a random Hentai episode
|
||||
* Done due to performance reasons
|
||||
*/
|
||||
public function random(): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
$random = Episode::inRandomOrder()
|
||||
->limit(1)
|
||||
->pluck('slug')
|
||||
->first();
|
||||
|
||||
return redirect()->route('hentai.index', [
|
||||
'title' => $random,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display Search Page.
|
||||
*/
|
||||
|
@@ -24,7 +24,6 @@
|
||||
@include('home.partials.random')
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Comments -->
|
||||
<div class="mx-auto pt-6 sm:px-6 lg:px-8 space-y-6 max-w-[100%] xl:max-w-[95%] 2xl:max-w-[85%] pb-2">
|
||||
@include('home.partials.comments')
|
||||
|
@@ -67,8 +67,7 @@
|
||||
@livewire('nav-live-search')
|
||||
<div class="hidden lg:block pl-4">
|
||||
<div class="flex flex-col items-center bg-gray-50/20 dark:bg-neutral-900/40 rounded-md">
|
||||
@php $random = App\Models\Episode::inRandomOrder()->limit(1)->pluck('slug')->first(); @endphp
|
||||
<a href="{{ route('hentai.index', ['title' => $random]) }}"
|
||||
<a href="{{ route('hentai.random') }}"
|
||||
class="cursor-pointer px-4 py-2 text-sm font-medium dark:hover:text-white text-gray-500 dark:text-white/90 focus:outline-none flex flex-col items-center md:flex-row">
|
||||
<i class="fa-solid fa-shuffle"></i>
|
||||
<p class="md:pl-1 pl-0">Random</p>
|
||||
|
@@ -22,6 +22,7 @@ use Illuminate\Support\Facades\Route;
|
||||
Route::get('/', [HomeController::class, 'index'])->name('home.index');
|
||||
Route::get('/stats', [HomeController::class, 'stats'])->name('home.stats');
|
||||
Route::get('/banned', [HomeController::class, 'banned'])->name('home.banned');
|
||||
Route::get('/random', [HomeController::class, 'random'])->name('hentai.random');
|
||||
|
||||
// API Endpoint
|
||||
Route::get('/v1/hentai-list', [HentaiApiController::class, 'index'])->name('api.hentai.index');
|
||||
|
Reference in New Issue
Block a user