Limit graphic stats to 6 months by default, some performance query improvements
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Collection;
|
||||
use MongoDB\BSON\UTCDateTime;
|
||||
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
@@ -14,6 +15,7 @@ class Domain extends Model
|
||||
{
|
||||
use HasFactory,ScopeActive;
|
||||
private const CACHE_TIME = 3600;
|
||||
private const STATS_MONTHS = 6;
|
||||
|
||||
/* SCOPES */
|
||||
|
||||
@@ -64,7 +66,10 @@ class Domain extends Model
|
||||
$key = sprintf('%s_%d','daily_area_stats',$this->id);
|
||||
|
||||
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);
|
||||
|
||||
@@ -83,7 +88,10 @@ class Domain extends Model
|
||||
$key = sprintf('%s_%d-%d','daily_echoarea_stats',$this->id,$o->id);
|
||||
|
||||
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);
|
||||
|
||||
@@ -103,6 +111,7 @@ class Domain extends Model
|
||||
|
||||
return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() use ($o) {
|
||||
$where = collect(['echoarea_id'=>$this->echoareas->pluck('id')->toArray()]);
|
||||
$where->put('datetime',['$gte',new UTCDateTime(Carbon::now()->subMonths(self::STATS_MONTHS)->startOfMonth())]);
|
||||
|
||||
if ($o)
|
||||
$where->put('fftn_id',$o->addresses()->pluck('id'));
|
||||
|
Reference in New Issue
Block a user