User dashboard caching

This commit is contained in:
Deon George 2021-11-26 17:19:55 +11:00
parent 6acc8ee407
commit 41d36fe86d
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
3 changed files with 29 additions and 20 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Events\Registered;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\User; use App\Models\User;
@ -50,7 +51,11 @@ class UserController extends Controller
public function dashboard() public function dashboard()
{ {
return view('dashboard'); $user = Auth::user();
$user->load('systems.addresses.zone.domain');
return view('dashboard')
->with('user',$user);
} }
public function home() public function home()

View File

@ -61,7 +61,7 @@ class Domain extends Model
if (! $this->echoareas->count()) if (! $this->echoareas->count())
return collect(); return collect();
$key = sprintf('%s_%d','daily_echoarea_stats',$this->id); $key = sprintf('%s_%d','daily_area_stats',$this->id);
return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() { return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() {
$where = ['echoarea_id'=>$this->echoareas->pluck('id')->toArray()]; $where = ['echoarea_id'=>$this->echoareas->pluck('id')->toArray()];
@ -99,24 +99,28 @@ class Domain extends Model
if (! $this->echoareas->count()) if (! $this->echoareas->count())
return collect(); return collect();
$where = collect(['echoarea_id'=>$this->echoareas->pluck('id')->toArray()]); $key = sprintf('%s_%d_%d','stats',$this->id,$o?->id);
if ($o) return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() use ($o) {
$where->put('fftn_id',$o->addresses()->pluck('id')); $where = collect(['echoarea_id'=>$this->echoareas->pluck('id')->toArray()]);
$echostats = Echomail::countGroupBy(['echoarea_id'],$where->toArray()); if ($o)
$where->put('fftn_id',$o->addresses()->pluck('id'));
return $this->echoareas->map(function($item) use ($echostats) { $echostats = Echomail::countGroupBy(['echoarea_id'],$where->toArray());
$stats = $echostats->filter(function($x) use ($item) {
return $x->id->echoarea_id == $item->id; return $this->echoareas->map(function($item) use ($echostats) {
$stats = $echostats->filter(function($x) use ($item) {
return $x->id->echoarea_id == $item->id;
});
$item->count = 0;
foreach ($stats as $o)
$item->count += $o->count;
return $item;
}); });
$item->count = 0;
foreach ($stats as $o)
$item->count += $o->count;
return $item;
}); });
} }
} }

View File

@ -161,7 +161,7 @@
name: 'Networks', name: 'Networks',
colorByPoint: true, colorByPoint: true,
data: [ data: [
@foreach($o->addresses->pluck('zone.domain')->sortBy('name') as $oo) @foreach(($xx=$user->systems->pluck('addresses')->flatten()->pluck('zone.domain')->sortBy('name')) as $oo)
@php($x = $oo->stats()) @php($x = $oo->stats())
{ {
name: '{{ $oo->name }}', name: '{{ $oo->name }}',
@ -176,7 +176,7 @@
colorByPoint: true, colorByPoint: true,
pointPlacement: 0.1, pointPlacement: 0.1,
data: [ data: [
@foreach($o->addresses->pluck('zone.domain')->sortBy('name') as $oo) @foreach($xx as $oo)
@php($x = $oo->stats($o)) @php($x = $oo->stats($o))
{ {
name: '{{ $oo->name }}', name: '{{ $oo->name }}',
@ -196,7 +196,7 @@
} }
}, },
series: [ series: [
@foreach($o->addresses->pluck('zone.domain')->sortBy('name') as $oo) @foreach($xx as $oo)
@php($x = $oo->stats()) @php($x = $oo->stats())
{ {
name: '{{ $oo->name }}', name: '{{ $oo->name }}',
@ -205,7 +205,7 @@
}, },
@endforeach @endforeach
@foreach($o->addresses->pluck('zone.domain')->sortBy('name') as $oo) @foreach($xx as $oo)
@php($x = $oo->stats($o)) @php($x = $oo->stats($o))
{ {
name: '{{ $oo->name }}', name: '{{ $oo->name }}',