Optimize anonymous public sessions
This commit is contained in:
@@ -151,6 +151,11 @@ class AppServiceProvider extends ServiceProvider
|
||||
$displayName = null;
|
||||
$userId = null;
|
||||
$toolbarContentTypes = collect();
|
||||
$request = request();
|
||||
$canReadSessionAuth = $request instanceof \Illuminate\Http\Request
|
||||
&& $request->hasSession()
|
||||
&& $request->attributes->get('skinbase.session_skipped') !== true;
|
||||
$authUser = $canReadSessionAuth ? Auth::user() : null;
|
||||
|
||||
try {
|
||||
$toolbarContentTypes = $this->app
|
||||
@@ -162,8 +167,9 @@ class AppServiceProvider extends ServiceProvider
|
||||
$toolbarContentTypes = collect();
|
||||
}
|
||||
|
||||
if (Auth::check()) {
|
||||
$userId = Auth::id();
|
||||
if ($authUser) {
|
||||
$authUser->loadMissing('profile');
|
||||
$userId = (int) $authUser->id;
|
||||
try {
|
||||
$uploadCount = DB::table('artworks')->where('user_id', $userId)->count();
|
||||
} catch (\Throwable $e) {
|
||||
@@ -200,19 +206,18 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
try {
|
||||
$receivedCommentsCount = $this->app->make(ReceivedCommentsInboxService::class)
|
||||
->unreadCountForUser(Auth::user());
|
||||
->unreadCountForUser($authUser);
|
||||
} catch (\Throwable $e) {
|
||||
$receivedCommentsCount = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
$profile = DB::table('user_profiles')->where('user_id', $userId)->first();
|
||||
$avatarHash = $profile->avatar_hash ?? null;
|
||||
$avatarHash = $authUser->profile?->avatar_hash;
|
||||
} catch (\Throwable $e) {
|
||||
$avatarHash = null;
|
||||
}
|
||||
|
||||
$displayName = Auth::user()->name ?: (Auth::user()->username ?? '');
|
||||
$displayName = $authUser->name ?: ($authUser->username ?? '');
|
||||
}
|
||||
|
||||
$view->with(compact('userId','uploadCount', 'favCount', 'msgCount', 'noticeCount', 'receivedCommentsCount', 'avatarHash', 'displayName', 'toolbarContentTypes'));
|
||||
|
||||
Reference in New Issue
Block a user