Dont use count(*) but rather count(column) so that indexes can help us
This commit is contained in:
parent
2d75c92afb
commit
832b496b0b
@ -453,7 +453,7 @@ class Address extends Model
|
|||||||
'node_id',
|
'node_id',
|
||||||
'point_id',
|
'point_id',
|
||||||
'system_id',
|
'system_id',
|
||||||
DB::raw('count(*) as uncollected_echomail'),
|
DB::raw('count(addresses.id) as uncollected_echomail'),
|
||||||
DB::raw('0 as uncollected_netmail'),
|
DB::raw('0 as uncollected_netmail'),
|
||||||
DB::raw('0 as uncollected_files'),
|
DB::raw('0 as uncollected_files'),
|
||||||
])
|
])
|
||||||
@ -490,7 +490,7 @@ class Address extends Model
|
|||||||
'system_id',
|
'system_id',
|
||||||
DB::raw('0 as uncollected_echomail'),
|
DB::raw('0 as uncollected_echomail'),
|
||||||
DB::raw('0 as uncollected_netmail'),
|
DB::raw('0 as uncollected_netmail'),
|
||||||
DB::raw('count(*) as uncollected_files')
|
DB::raw('count(addresses.id) as uncollected_files')
|
||||||
])
|
])
|
||||||
->UncollectedFiles();
|
->UncollectedFiles();
|
||||||
}
|
}
|
||||||
@ -528,7 +528,7 @@ class Address extends Model
|
|||||||
'point_id',
|
'point_id',
|
||||||
'system_id',
|
'system_id',
|
||||||
DB::raw('0 as uncollected_echomail'),
|
DB::raw('0 as uncollected_echomail'),
|
||||||
DB::raw('count(*) as uncollected_netmail'),
|
DB::raw('count(addresses.id) as uncollected_netmail'),
|
||||||
DB::raw('0 as uncollected_files')
|
DB::raw('0 as uncollected_files')
|
||||||
])
|
])
|
||||||
->UncollectedNetmail();
|
->UncollectedNetmail();
|
||||||
|
@ -110,7 +110,7 @@ class Domain extends Model
|
|||||||
{
|
{
|
||||||
return Cache::remember(md5(sprintf('%d-%s',$this->id,$systems?->pluck('id')->join(','))),self::CACHE_TIME,function() use ($systems) {
|
return Cache::remember(md5(sprintf('%d-%s',$this->id,$systems?->pluck('id')->join(','))),self::CACHE_TIME,function() use ($systems) {
|
||||||
return DB::query()
|
return DB::query()
|
||||||
->select(['echoareas.name','echoareas.show',DB::raw('COUNT(*) AS count'),DB::raw('datetime::date AS date')])
|
->select(['echoareas.name','echoareas.show',DB::raw('COUNT(echoareas.name) AS count'),DB::raw('datetime::date AS date')])
|
||||||
->from($this->getTable())
|
->from($this->getTable())
|
||||||
->join('echoareas',['echoareas.domain_id'=>'domains.id'])
|
->join('echoareas',['echoareas.domain_id'=>'domains.id'])
|
||||||
->join('echomails',['echomails.echoarea_id'=>'echoareas.id'])
|
->join('echomails',['echomails.echoarea_id'=>'echoareas.id'])
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
@php
|
|
||||||
use App\Models\Address;
|
|
||||||
@endphp
|
|
||||||
|
|
||||||
<!-- $o=System::class -->
|
<!-- $o=System::class -->
|
||||||
|
@use(App\Models\Address)
|
||||||
|
@use(App\Models\Echomail)
|
||||||
|
@use(App\Models\File)
|
||||||
|
@use(App\Models\Netmail)
|
||||||
|
|
||||||
@extends('layouts.app')
|
@extends('layouts.app')
|
||||||
|
|
||||||
@section('htmlheader_title')
|
@section('htmlheader_title')
|
||||||
@ -390,7 +391,7 @@ use App\Models\Address;
|
|||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
The last Netmails sent (to you):
|
The last Netmails sent (to you):
|
||||||
|
|
||||||
@if(($x=\App\Models\Netmail::select(['sent_pkt','sent_at',DB::raw('count(*) AS count')])
|
@if(($x=Netmail::select(['sent_pkt','sent_at',DB::raw('count(sent_pkt) AS count')])
|
||||||
->whereIn('sent_id',$o->addresses->pluck('id'))
|
->whereIn('sent_id',$o->addresses->pluck('id'))
|
||||||
->whereNotNull('sent_at')
|
->whereNotNull('sent_at')
|
||||||
->groupBy(['sent_pkt','sent_at'])
|
->groupBy(['sent_pkt','sent_at'])
|
||||||
@ -425,7 +426,7 @@ use App\Models\Address;
|
|||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
The last Echomails sent (to you):
|
The last Echomails sent (to you):
|
||||||
|
|
||||||
@if(($x=\App\Models\Echomail::select(['sent_pkt','sent_at',DB::raw('count(*) AS count')])
|
@if(($x=Echomail::select(['sent_pkt','sent_at',DB::raw('count(sent_pkt) AS count')])
|
||||||
->join('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id'])
|
->join('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id'])
|
||||||
->whereNotNull('sent_at')
|
->whereNotNull('sent_at')
|
||||||
->whereIn('address_id',$o->addresses->pluck('id'))
|
->whereIn('address_id',$o->addresses->pluck('id'))
|
||||||
@ -460,7 +461,7 @@ use App\Models\Address;
|
|||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
The last Files sent (to you):
|
The last Files sent (to you):
|
||||||
|
|
||||||
@if(($x=\App\Models\File::select(['sent_at',DB::raw('count(*) AS count')])
|
@if(($x=File::select(['sent_at',DB::raw('count(sent_at) AS count')])
|
||||||
->join('file_seenby',['file_seenby.file_id'=>'files.id'])
|
->join('file_seenby',['file_seenby.file_id'=>'files.id'])
|
||||||
->whereNotNull('sent_at')
|
->whereNotNull('sent_at')
|
||||||
->whereIn('address_id',$o->addresses->pluck('id'))
|
->whereIn('address_id',$o->addresses->pluck('id'))
|
||||||
@ -495,7 +496,7 @@ use App\Models\Address;
|
|||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
The last Netmails received (you sent):
|
The last Netmails received (you sent):
|
||||||
|
|
||||||
@if(($x=\App\Models\Netmail::select(['recv_pkt','recv_at',DB::raw('count(*) AS count')])
|
@if(($x=Netmail::select(['recv_pkt','recv_at',DB::raw('count(recv_pkt) AS count')])
|
||||||
->join('netmail_path',['netmail_path.netmail_id'=>'netmails.id'])
|
->join('netmail_path',['netmail_path.netmail_id'=>'netmails.id'])
|
||||||
->whereIn('address_id',$o->addresses->pluck('id'))
|
->whereIn('address_id',$o->addresses->pluck('id'))
|
||||||
->groupBy(['recv_pkt','recv_at'])
|
->groupBy(['recv_pkt','recv_at'])
|
||||||
@ -529,7 +530,7 @@ use App\Models\Address;
|
|||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
The last Echomails received (you sent):
|
The last Echomails received (you sent):
|
||||||
|
|
||||||
@if(($x=\App\Models\Echomail::select(['recv_pkt','recv_at',DB::raw('count(*) AS count')])
|
@if(($x=Echomail::select(['recv_pkt','recv_at',DB::raw('count(recv_pkt) AS count')])
|
||||||
->join('echomail_path',['echomail_path.echomail_id'=>'echomails.id'])
|
->join('echomail_path',['echomail_path.echomail_id'=>'echomails.id'])
|
||||||
->whereNotNull('recv_pkt')
|
->whereNotNull('recv_pkt')
|
||||||
->whereIn('address_id',$o->addresses->pluck('id'))
|
->whereIn('address_id',$o->addresses->pluck('id'))
|
||||||
@ -564,7 +565,7 @@ use App\Models\Address;
|
|||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
The last Files received (from you):
|
The last Files received (from you):
|
||||||
|
|
||||||
@if(($x=\App\Models\File::select(['created_at',DB::raw('count(*) AS count')])
|
@if(($x=File::select(['created_at',DB::raw('count(created_at) AS count')])
|
||||||
->whereIn('fftn_id',$o->addresses->pluck('id'))
|
->whereIn('fftn_id',$o->addresses->pluck('id'))
|
||||||
->groupBy(['created_at'])
|
->groupBy(['created_at'])
|
||||||
->orderBy('created_at','DESC')
|
->orderBy('created_at','DESC')
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<!-- $o=System::class -->
|
<!-- $o=System::class -->
|
||||||
|
@use(App\Models\Echoarea)
|
||||||
|
|
||||||
@extends('layouts.app')
|
@extends('layouts.app')
|
||||||
@section('htmlheader_title')
|
@section('htmlheader_title')
|
||||||
Systems
|
Systems
|
||||||
@ -80,7 +82,7 @@
|
|||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach($o->addresses->sortBy('zone.domain.name')->groupBy('zone.domain_id') as $did => $domain_addresses)
|
@foreach($o->addresses->sortBy('zone.domain.name')->groupBy('zone.domain_id') as $did => $domain_addresses)
|
||||||
@foreach(\App\Models\Echoarea::select([DB::raw('count(echomails.*) as count'),DB::raw('max(echomails.datetime) as most_recent')])
|
@foreach(Echoarea::select([DB::raw('count(echomails.id) as count'),DB::raw('max(echomails.datetime) as most_recent')])
|
||||||
->join('echomails',['echomails.echoarea_id'=>'echoareas.id'])
|
->join('echomails',['echomails.echoarea_id'=>'echoareas.id'])
|
||||||
->join('echomail_seenby',function($join) use ($domain_addresses) {
|
->join('echomail_seenby',function($join) use ($domain_addresses) {
|
||||||
return $join->on('echomail_seenby.echomail_id','echomails.id')
|
return $join->on('echomail_seenby.echomail_id','echomails.id')
|
||||||
|
Loading…
Reference in New Issue
Block a user