feat: cache team settings

This commit is contained in:
Andras Bacsai 2023-09-08 18:33:26 +02:00
parent 0d1a2aa5d1
commit 45b597bbab
5 changed files with 17 additions and 6 deletions

View File

@ -6,6 +6,7 @@
use App\Models\PrivateKey;
use App\Models\Project;
use App\Models\Server;
use App\Models\Team;
use Illuminate\Support\Collection;
use Livewire\Component;
@ -70,9 +71,10 @@ public function restartBoarding()
}
public function skipBoarding()
{
currentTeam()->update([
Team::find(currentTeam()->id)->update([
'show_boarding' => false
]);
ray(currentTeam());
refreshSession();
return redirect()->route('dashboard');
}

View File

@ -23,7 +23,7 @@ public function switch_to($team_id)
if (!$team_to_switch_to) {
return;
}
session(['currentTeam' => $team_to_switch_to]);
refreshSession($team_to_switch_to);
return redirect(request()->header('Referer'));
}
}

View File

@ -15,7 +15,7 @@ class IsBoardingFlow
*/
public function handle(Request $request, Closure $next): Response
{
// ray()->showQueries()->color('orange');
ray()->showQueries()->color('orange');
if (showBoarding() && !in_array($request->path(), allowedPathsForBoardingAccounts())) {
return redirect('boarding');
}

View File

@ -4,6 +4,7 @@
use App\Notifications\Channels\SendsEmail;
use App\Notifications\TransactionalEmails\ResetPassword as TransactionalEmailsResetPassword;
use Cache;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@ -94,7 +95,9 @@ public function isInstanceAdmin()
public function currentTeam()
{
return Team::find(session('currentTeam')->id);
return Cache::remember('team:' . auth()->user()->id, 3600, function() {
return Team::find(session('currentTeam')->id);
});
}
public function otherTeams()

View File

@ -57,9 +57,15 @@ function showBoarding(): bool
{
return currentTeam()->show_boarding ?? false;
}
function refreshSession(): void
function refreshSession(?Team $team = null): void
{
$team = Team::find(currentTeam()->id);
if (!$team) {
$team = Team::find(currentTeam()->id);
}
Cache::forget('team:' . auth()->user()->id);
Cache::remember('team:' . auth()->user()->id, 3600, function() use ($team) {
return $team;
});
session(['currentTeam' => $team]);
}
function general_error_handler(Throwable | null $err = null, $that = null, $isJson = false, $customErrorMessage = null): mixed