mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Add indexes and caching for admin pages
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class BasePageController extends Controller
|
||||
@@ -50,25 +51,34 @@ class BasePageController extends Controller
|
||||
{
|
||||
$this->middleware(['auth', 'web', '2fa'])->except('api', 'contact', 'showContactForm', 'callback', 'btcPayCallback', 'getNzb', 'terms', 'privacyPolicy', 'capabilities', 'movie', 'apiSearch', 'tv', 'details', 'failed', 'showRssDesc', 'fullFeedRss', 'categoryFeedRss', 'cartRss', 'myMoviesRss', 'myShowsRss', 'trendingMoviesRss', 'trendingShowsRss', 'release', 'reset', 'showLinkRequestForm');
|
||||
|
||||
// Load settings as collection
|
||||
$this->settings = Settings::query()->pluck('value', 'name');
|
||||
// Load settings as collection with caching (5 minutes)
|
||||
$this->settings = Cache::remember('site_settings', 300, function () {
|
||||
return Settings::query()->pluck('value', 'name');
|
||||
});
|
||||
|
||||
// Initialize view data FIRST with serverroot
|
||||
$this->viewData = [
|
||||
'serverroot' => url('/'),
|
||||
];
|
||||
|
||||
// Then add the converted settings array as 'site'
|
||||
// Using array assignment instead of constructor assignment to ensure it persists
|
||||
$this->viewData['site'] = $this->settings->map(function ($value) {
|
||||
return Settings::convertValue($value);
|
||||
})->all();
|
||||
// Then add the converted settings array as 'site' with caching
|
||||
$this->viewData['site'] = Cache::remember('site_settings_converted', 300, function () {
|
||||
return $this->settings->map(function ($value) {
|
||||
return Settings::convertValue($value);
|
||||
})->all();
|
||||
});
|
||||
|
||||
// Initialize userdata property for controllers that need it
|
||||
$this->middleware(function ($request, $next) {
|
||||
if (Auth::check()) {
|
||||
$this->userdata = User::find(Auth::id());
|
||||
$this->userdata->categoryexclusions = User::getCategoryExclusionById(Auth::id());
|
||||
$userId = Auth::id();
|
||||
$this->userdata = User::find($userId);
|
||||
// Cache category exclusions per user (5 minutes)
|
||||
$this->userdata->categoryexclusions = Cache::remember(
|
||||
'user_category_exclusions_'.$userId,
|
||||
300,
|
||||
fn () => User::getCategoryExclusionById($userId)
|
||||
);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
Reference in New Issue
Block a user