Limit graphic stats to 6 months by default, some performance query improvements
This commit is contained in:
parent
bf57f151d5
commit
10afd6f3a4
@ -52,7 +52,7 @@ class UserController extends Controller
|
|||||||
public function dashboard()
|
public function dashboard()
|
||||||
{
|
{
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
$user->load('systems.addresses.zone.domain');
|
$user->load('systems.addresses.zone.domain.echoareas');
|
||||||
|
|
||||||
return view('dashboard')
|
return view('dashboard')
|
||||||
->with('user',$user);
|
->with('user',$user);
|
||||||
|
@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use MongoDB\BSON\UTCDateTime;
|
||||||
|
|
||||||
use App\Traits\ScopeActive;
|
use App\Traits\ScopeActive;
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ class Domain extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory,ScopeActive;
|
use HasFactory,ScopeActive;
|
||||||
private const CACHE_TIME = 3600;
|
private const CACHE_TIME = 3600;
|
||||||
|
private const STATS_MONTHS = 6;
|
||||||
|
|
||||||
/* SCOPES */
|
/* SCOPES */
|
||||||
|
|
||||||
@ -64,7 +66,10 @@ class Domain extends Model
|
|||||||
$key = sprintf('%s_%d','daily_area_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(),
|
||||||
|
'datetime' => ['$gte',new UTCDateTime(Carbon::now()->subMonths(self::STATS_MONTHS)->startOfMonth())],
|
||||||
|
];
|
||||||
|
|
||||||
$echostats = Echomail::countGroupBy(['datetime',['datetime'=>'%Y-%m-%d']],$where);
|
$echostats = Echomail::countGroupBy(['datetime',['datetime'=>'%Y-%m-%d']],$where);
|
||||||
|
|
||||||
@ -83,7 +88,10 @@ class Domain extends Model
|
|||||||
$key = sprintf('%s_%d-%d','daily_echoarea_stats',$this->id,$o->id);
|
$key = sprintf('%s_%d-%d','daily_echoarea_stats',$this->id,$o->id);
|
||||||
|
|
||||||
return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() use ($o) {
|
return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() use ($o) {
|
||||||
$where = ['echoarea_id'=>[$o->id]];
|
$where = [
|
||||||
|
'echoarea_id'=>[$o->id],
|
||||||
|
'datetime' => ['$gte',new UTCDateTime(Carbon::now()->subMonths(self::STATS_MONTHS)->startOfMonth())],
|
||||||
|
];
|
||||||
|
|
||||||
$echostats = Echomail::countGroupBy(['datetime',['datetime'=>'%Y-%m-%d']],$where);
|
$echostats = Echomail::countGroupBy(['datetime',['datetime'=>'%Y-%m-%d']],$where);
|
||||||
|
|
||||||
@ -103,6 +111,7 @@ class Domain extends Model
|
|||||||
|
|
||||||
return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() use ($o) {
|
return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() use ($o) {
|
||||||
$where = collect(['echoarea_id'=>$this->echoareas->pluck('id')->toArray()]);
|
$where = collect(['echoarea_id'=>$this->echoareas->pluck('id')->toArray()]);
|
||||||
|
$where->put('datetime',['$gte',new UTCDateTime(Carbon::now()->subMonths(self::STATS_MONTHS)->startOfMonth())]);
|
||||||
|
|
||||||
if ($o)
|
if ($o)
|
||||||
$where->put('fftn_id',$o->addresses()->pluck('id'));
|
$where->put('fftn_id',$o->addresses()->pluck('id'));
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
namespace App\Traits;
|
namespace App\Traits;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
trait UseMongo
|
trait UseMongo
|
||||||
{
|
{
|
||||||
@ -56,11 +57,21 @@ trait UseMongo
|
|||||||
if (! is_array($values))
|
if (! is_array($values))
|
||||||
throw new \Exception('Where values must be an array.');
|
throw new \Exception('Where values must be an array.');
|
||||||
|
|
||||||
|
switch ($x=Arr::get($values,0)) {
|
||||||
|
case '$gt':
|
||||||
|
case '$gte':
|
||||||
|
$where_condition[$key] = [ $x => Arr::get($values,1)];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '$in':
|
||||||
|
default:
|
||||||
$where_condition[$key] = ['$in' => $values];
|
$where_condition[$key] = ['$in' => $values];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$query->push([
|
$query->push([
|
||||||
'$match' => $where_condition
|
'$match' => [ '$and'=> [$where_condition]]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ If you have more than 1 BBS, then the Clearing House can receive all your mail f
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
series: [
|
series: [
|
||||||
@foreach (\App\Models\Domain::active()->public()->get() as $o)
|
@foreach (\App\Models\Domain::active()->public()->with(['echoareas'])->get() as $o)
|
||||||
{
|
{
|
||||||
name: '{{ $o->name }}',
|
name: '{{ $o->name }}',
|
||||||
data: {!! $o->daily_area_stats() !!},
|
data: {!! $o->daily_area_stats() !!},
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
@extends('layouts.app')
|
@extends('layouts.app')
|
||||||
|
@section('htmlheader_title')
|
||||||
|
Message View
|
||||||
|
@endsection
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<h3>Echomail</h3>
|
<h3>Echomail</h3>
|
||||||
|
Loading…
Reference in New Issue
Block a user