From 50d4b8b3e251e291654b42941341826eaa24bf15 Mon Sep 17 00:00:00 2001 From: cp6 Date: Mon, 18 Jul 2022 14:27:11 +1000 Subject: [PATCH] Added YABs compare & implemented cache for YABs Added YABs compare Made YABs calls use relationship with disk and network table Update YABs views to reflect access changes in data Implemented cache for YABs Added Server function serverYabsAmount() to count YABs for a server id --- app/Http/Controllers/YabsController.php | 56 ++-- app/Models/Server.php | 7 + app/Models/Yabs.php | 31 +++ resources/views/yabs/choose-compare.blade.php | 77 ++++++ resources/views/yabs/compare.blade.php | 244 ++++++++++++++++++ resources/views/yabs/index.blade.php | 13 +- resources/views/yabs/show.blade.php | 20 +- routes/web.php | 4 + 8 files changed, 416 insertions(+), 36 deletions(-) create mode 100644 resources/views/yabs/choose-compare.blade.php create mode 100644 resources/views/yabs/compare.blade.php diff --git a/app/Http/Controllers/YabsController.php b/app/Http/Controllers/YabsController.php index 1eab347..5658589 100644 --- a/app/Http/Controllers/YabsController.php +++ b/app/Http/Controllers/YabsController.php @@ -16,11 +16,7 @@ class YabsController extends Controller { public function index() { - $yabs = DB::table('yabs as y') - ->join('servers as s', 'y.server_id', '=', 's.id') - ->Join('disk_speed as ds', 'y.id', '=', 'ds.id') - ->get(['y.*', 's.hostname', 'ds.*']); - + $yabs = Yabs::allYabs(); return view('yabs.index', compact(['yabs'])); } @@ -38,7 +34,6 @@ class YabsController extends Controller if (isset($yabs['error_id'])) { return back()->withErrors(["yabs" => 'Problem inserting YABs. Error id ' . $yabs['error_id']])->withInput(); - //return redirect()->route('yabs.index')->with('error', 'Problem inserting YABs. Error id ' . $yabs['error_id']); } //No errors, do insert @@ -111,6 +106,7 @@ class YabsController extends Controller Cache::forget('all_active_servers');//all servers cache Cache::forget('non_active_servers');//all servers cache + Cache::forget('all_yabs');//Forget the all YABs cache return redirect()->route('yabs.index') ->with('success', 'Success inserting YABs'); @@ -118,17 +114,8 @@ class YabsController extends Controller public function show(Yabs $yab) { - $yab = DB::table('yabs as y') - ->join('servers as s', 'y.server_id', '=', 's.id') - ->join('disk_speed as ds', 'y.id', '=', 'ds.id') - ->where('y.id', '=', $yab->id) - ->get(['y.*', 's.hostname', 'ds.*']); - - $network = DB::table('network_speed') - ->where('id', '=', $yab[0]->id) - ->get(); - - return view('yabs.show', compact(['yab', 'network'])); + $yab = Yabs::yabs($yab->id); + return view('yabs.show', compact(['yab'])); } public function destroy(Yabs $yab) @@ -136,11 +123,40 @@ class YabsController extends Controller $yabs = Yabs::find($yab->id); $yabs->delete(); - $update_server = DB::table('servers') - ->where('id', $yab->server_id) - ->update(['has_yabs' => 0]); + if (Server::serverYabsAmount($yab->server_id) === 0) { + DB::table('servers') + ->where('id', $yab->server_id) + ->update(['has_yabs' => 0]); + } + + Cache::forget('all_yabs'); + Cache::forget("yabs.{$yab->id}"); return redirect()->route('yabs.index') ->with('success', 'YABs was deleted Successfully.'); } + + public function chooseYabsCompare() + { + $all_yabs = Yabs::allYabs(); + return view('yabs.choose-compare', compact('all_yabs')); + } + + public function compareYabs($yabs1, $yabs2) + { + $yabs1_data = Yabs::yabs($yabs1); + + if (count($yabs1_data) === 0) { + return response()->view('errors.404', array("status" => 404, "title" => "Page not found", "message" => "No YABs data was found for id '$yabs1'"), 404); + } + + $yabs2_data = Yabs::yabs($yabs2); + + if (count($yabs2_data) === 0) { + return response()->view('errors.404', array("status" => 404, "title" => "Page not found", "message" => "No YABs data was found for id '$server2'"), 404); + } + + return view('yabs.compare', compact('yabs1_data', 'yabs2_data')); + } + } diff --git a/app/Models/Server.php b/app/Models/Server.php index 40396e3..06a8f82 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -249,4 +249,11 @@ class Server extends Model }); } + public static function serverYabsAmount(string $server_id): int + { + return DB::table('yabs') + ->where('server_id', '=', $server_id) + ->get()->count(); + } + } diff --git a/app/Models/Yabs.php b/app/Models/Yabs.php index b93186d..3010313 100644 --- a/app/Models/Yabs.php +++ b/app/Models/Yabs.php @@ -35,4 +35,35 @@ class Yabs extends Model }); } + public static function yabs(string $yabs_id) + { + return Cache::remember("yabs.$yabs_id", now()->addMonth(1), function () use ($yabs_id) { + return self::where('id', $yabs_id)->with(['server', 'disk_speed', 'network_speed']) + ->get(); + }); + } + + public static function allYabs() + { + return Cache::remember("all_yabs", now()->addMonth(1), function () { + return self::with(['server', 'disk_speed', 'network_speed']) + ->get(); + }); + } + + public function server() + { + return $this->hasOne(Server::class, 'id', 'server_id'); + } + + public function disk_speed() + { + return $this->hasOne(DiskSpeed::class, 'id', 'id'); + } + + public function network_speed() + { + return $this->hasMany(NetworkSpeed::class, 'id', 'id'); + } + } diff --git a/resources/views/yabs/choose-compare.blade.php b/resources/views/yabs/choose-compare.blade.php new file mode 100644 index 0000000..e0b3cce --- /dev/null +++ b/resources/views/yabs/choose-compare.blade.php @@ -0,0 +1,77 @@ +@section('title') + {{'Choose YABs to compare'}} +@endsection +@section('scripts') + +@endsection + + + {{ __('Choose two YABs to compare') }} + +
+
+
+ YABs home + @if(count($all_yabs) >= 2) +
+
+
+
YABs 1
+ +
+
+
+
+
YABs 2
+ +
+
+
+ View comparison table + @else +

You need to have added at least 2 YABs to use this feature

+ @endif +
+
+ @if(Session::has('timer_version_footer') && Session::get('timer_version_footer') === 1) +

Built on Laravel + v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }})

+ @endif +
+ +
diff --git a/resources/views/yabs/compare.blade.php b/resources/views/yabs/compare.blade.php new file mode 100644 index 0000000..29245c6 --- /dev/null +++ b/resources/views/yabs/compare.blade.php @@ -0,0 +1,244 @@ +@section('title') {{'Compare YABs'}} @endsection +@section('style') + +@endsection + +
+
+
+ Choose others +
+ + + + + + + + + + + + + + + + + + + + + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->cpu_cores, $yabs2_data[0]->cpu_cores, ' cores') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->cpu_freq, $yabs2_data[0]->cpu_freq, 'Mhz') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->ram_mb, $yabs2_data[0]->ram_mb, 'MB') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->disk_gb, $yabs2_data[0]->disk_gb, 'GB') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->gb5_single, $yabs2_data[0]->gb5_single, '') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->gb5_multi, $yabs2_data[0]->gb5_multi, '') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->disk_speed->d_4k_as_mbps, $yabs2_data[0]->disk_speed->d_4k_as_mbps, 'MB/s') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->disk_speed->d_64k_as_mbps, $yabs2_data[0]->disk_speed->d_64k_as_mbps, 'MB/s') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->disk_speed->d_512k_as_mbps, $yabs2_data[0]->disk_speed->d_512k_as_mbps, 'MB/s') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->disk_speed->d_1m_as_mbps, $yabs2_data[0]->disk_speed->d_1m_as_mbps, 'MB/s') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[0]->send_as_mbps, $yabs2_data[0]->network_speed[0]->send_as_mbps, 'MBps') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[0]->receive_as_mbps, $yabs2_data[0]->network_speed[0]->receive_as_mbps, 'MBps') !!} + + + @if($yabs1_data[0]->network_speed[1]->location === $yabs2_data[0]->network_speed[1]->location) + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[1]->send_as_mbps, $yabs2_data[0]->network_speed[1]->send_as_mbps, 'MBps') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[1]->receive_as_mbps, $yabs2_data[0]->network_speed[1]->receive_as_mbps, 'MBps') !!} + + + @endif + @if($yabs1_data[0]->network_speed[2]->location === $yabs2_data[0]->network_speed[2]->location) + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[2]->send_as_mbps, $yabs2_data[0]->network_speed[2]->send_as_mbps, 'MBps') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[2]->receive_as_mbps, $yabs2_data[0]->network_speed[2]->receive_as_mbps, 'MBps') !!} + + + @endif + @if($yabs1_data[0]->network_speed[3]->location === $yabs2_data[0]->network_speed[3]->location) + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[3]->send_as_mbps, $yabs2_data[0]->network_speed[3]->send_as_mbps, 'MBps') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[3]->receive_as_mbps, $yabs2_data[0]->network_speed[3]->receive_as_mbps, 'MBps') !!} + + + @endif + @if($yabs1_data[0]->network_speed[4]->location === $yabs2_data[0]->network_speed[4]->location) + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[4]->send_as_mbps, $yabs2_data[0]->network_speed[4]->send_as_mbps, 'MBps') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[4]->receive_as_mbps, $yabs2_data[0]->network_speed[4]->receive_as_mbps, 'MBps') !!} + + + @endif + @if($yabs1_data[0]->network_speed[4]->location === $yabs2_data[0]->network_speed[5]->location) + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[4]->send_as_mbps, $yabs2_data[0]->network_speed[5]->send_as_mbps, 'MBps') !!} + + + + + + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[4]->receive_as_mbps, $yabs2_data[0]->network_speed[5]->receive_as_mbps, 'MBps') !!} + + + @endif + +
{{ $yabs1_data[0]->id }}DIF{{ $yabs2_data[0]->id}}
Date{{ date_format(new DateTime($yabs1_data[0]->output_date), 'g:ia D jS F Y') }} + {{\Carbon\Carbon::parse($yabs1_data[0]->output_date)->diffForHumans(\Carbon\Carbon::parse($yabs2_data[0]->output_date))}} + {{ date_format(new DateTime($yabs2_data[0]->output_date), 'g:ia D jS F Y') }}
Server{{$yabs1_data[0]->server->hostname}}{{$yabs2_data[0]->server->hostname}}
CPU count{{$yabs1_data[0]->cpu_cores}}{{$yabs2_data[0]->cpu_cores}}
CPU freq{{$yabs1_data[0]->cpu_freq}}Mhz{{$yabs2_data[0]->cpu_freq}}Mhz
Ram{{$yabs1_data[0]->ram_mb}}MB{{$yabs2_data[0]->ram_mb}}MB
Disk{{$yabs1_data[0]->disk_gb}}GB{{$yabs2_data[0]->disk_gb}}GB
GB5 single{{$yabs1_data[0]->gb5_single}}{{$yabs2_data[0]->gb5_single}}
GB5 multi{{$yabs1_data[0]->gb5_multi}}{{$yabs2_data[0]->gb5_multi}}
4k disk{{$yabs1_data[0]->disk_speed->d_4k_as_mbps}}MB/s + {{$yabs2_data[0]->disk_speed->d_4k_as_mbps}}MB/s +
64k disk{{$yabs1_data[0]->disk_speed->d_64k_as_mbps}}MB/s + {{$yabs2_data[0]->disk_speed->d_64k_as_mbps}}MB/s +
512k disk{{$yabs1_data[0]->disk_speed->d_512k_as_mbps}}MB/s{{$yabs2_data[0]->disk_speed->d_512k_as_mbps}}MB/s
1m disk{{$yabs1_data[0]->disk_speed->d_1m_as_mbps}}MB/s + {{$yabs2_data[0]->disk_speed->d_1m_as_mbps}}MB/s +
{{$yabs1_data[0]->network_speed[0]->location}} send{{$yabs1_data[0]->network_speed[0]->send_as_mbps}}MBps{{$yabs2_data[0]->network_speed[0]->send_as_mbps}}MBps
{{$yabs1_data[0]->network_speed[0]->location}} receive{{$yabs1_data[0]->network_speed[0]->receive_as_mbps}}MBps{{$yabs2_data[0]->network_speed[0]->receive_as_mbps}}MBps
{{$yabs1_data[0]->network_speed[1]->location}} send{{$yabs1_data[0]->network_speed[1]->send_as_mbps}}MBps{{$yabs2_data[0]->network_speed[1]->send_as_mbps}}MBps
{{$yabs1_data[0]->network_speed[1]->location}} receive{{$yabs1_data[0]->network_speed[1]->receive_as_mbps}}MBps + {{$yabs2_data[0]->network_speed[1]->receive_as_mbps}}MBps +
{{$yabs1_data[0]->network_speed[2]->location}} send{{$yabs1_data[0]->network_speed[2]->send_as_mbps}}MBps{{$yabs2_data[0]->network_speed[2]->send_as_mbps}}MBps
{{$yabs1_data[0]->network_speed[2]->location}} receive{{$yabs1_data[0]->network_speed[2]->receive_as_mbps}}MBps + {{$yabs2_data[0]->network_speed[2]->receive_as_mbps}}MBps +
{{$yabs1_data[0]->network_speed[3]->location}} send{{$yabs1_data[0]->network_speed[3]->send_as_mbps}}MBps{{$yabs2_data[0]->network_speed[3]->send_as_mbps}}MBps
{{$yabs1_data[0]->network_speed[3]->location}} receive{{$yabs1_data[0]->network_speed[3]->receive_as_mbps}}MBps + {{$yabs2_data[0]->network_speed[3]->receive_as_mbps}}MBps +
{{$yabs1_data[0]->network_speed[4]->location}} send{{$yabs1_data[0]->network_speed[4]->send_as_mbps}}MBps{{$yabs2_data[0]->network_speed[4]->send_as_mbps}}MBps
{{$yabs1_data[0]->network_speed[4]->location}} receive{{$yabs1_data[0]->network_speed[4]->receive_as_mbps}}MBps + {{$yabs2_data[0]->network_speed[4]->receive_as_mbps}}MBps +
{{$yabs1_data[0]->network_speed[4]->location}} send{{$yabs1_data[0]->network_speed[4]->send_as_mbps}}MBps{{$yabs2_data[0]->network_speed[5]->send_as_mbps}}MBps
{{$yabs1_data[0]->network_speed[4]->location}} receive{{$yabs1_data[0]->network_speed[4]->receive_as_mbps}}MBps + {{$yabs2_data[0]->network_speed[5]->receive_as_mbps}}MBps +
+
+
+
+
+
diff --git a/resources/views/yabs/index.blade.php b/resources/views/yabs/index.blade.php index f18a090..aa284cc 100644 --- a/resources/views/yabs/index.blade.php +++ b/resources/views/yabs/index.blade.php @@ -14,6 +14,7 @@ Add YABs + Compare YABs
@@ -40,7 +41,7 @@ @if(!empty($yabs)) @foreach($yabs as $yab) - {{ $yab->hostname }} + {{ $yab->server->hostname }} {{ $yab->cpu_cores }} {{ $yab->cpu_freq }}Mhz {{ $yab->ram }}{{ $yab->ram_type }} @@ -53,10 +54,10 @@ No @endif - {{ $yab->d_4k }}{{ $yab->d_4k_type }} - {{ $yab->d_64k }}{{ $yab->d_64k_type }} - {{ $yab->d_512k }}{{ $yab->d_512k_type }} - {{ $yab->d_1m }}{{ $yab->d_1m_type }} + {{ $yab->disk_speed->d_4k }}{{ $yab->disk_speed->d_4k_type }} + {{ $yab->disk_speed->d_64k }}{{ $yab->disk_speed->d_64k_type }} + {{ $yab->disk_speed->d_512k }}{{ $yab->disk_speed->d_512k_type }} + {{ $yab->disk_speed->d_1m }}{{ $yab->disk_speed->d_1m_type }} {{ date_format(new DateTime($yab->output_date), 'Y-m-d g:i a') }}
@@ -66,7 +67,7 @@ + id="btn-{{$yab->server->hostname}}" title="{{$yab->id}}">
diff --git a/resources/views/yabs/show.blade.php b/resources/views/yabs/show.blade.php index cff5421..35f8475 100644 --- a/resources/views/yabs/show.blade.php +++ b/resources/views/yabs/show.blade.php @@ -16,7 +16,7 @@ Server - {{ $yab[0]->hostname }} + {{ $yab[0]->server->hostname }} CPU @@ -75,10 +75,10 @@ class="text-decoration-none">{{ $yab[0]->gb5_multi }} - Tested + Test ran @if(!is_null($yab[0]->output_date)) - {{date_format(new DateTime($yab[0]->output_date), 'jS F Y')}} + {{date_format(new DateTime($yab[0]->output_date), 'g:ia D jS F Y')}} @endif @@ -93,25 +93,25 @@ Disk speeds: - 4k {{$yab[0]->d_4k}} - {{$yab[0]->d_4k_type}} + 4k {{$yab[0]->disk_speed->d_4k}} + {{$yab[0]->disk_speed->d_4k_type}} - 64k {{$yab[0]->d_64k}} - {{$yab[0]->d_64k_type}} + 64k {{$yab[0]->disk_speed->d_64k}} + {{$yab[0]->disk_speed->d_64k_type}} - 512k {{$yab[0]->d_512k}} + 512k {{$yab[0]->disk_speed->d_512k}} {{$yab[0]->d_512k_type}} - 1m {{$yab[0]->d_1m}} {{$yab[0]->d_1m_type}} + 1m {{$yab[0]->disk_speed->d_1m}} {{$yab[0]->disk_speed->d_1m_type}} Network speed (location|send|receive): - @foreach($network as $speed_test) + @foreach($yab[0]->network_speed as $speed_test) {{$speed_test->location}} {{$speed_test->send}} diff --git a/routes/web.php b/routes/web.php index db71eaa..f3ef6b8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -70,6 +70,10 @@ Route::resource('shared', SharedController::class)->middleware(['auth']); Route::resource('yabs', YabsController::class)->middleware(['auth']); +Route::get('yabs-compare-choose', 'App\Http\Controllers\YabsController@chooseYabsCompare')->middleware(['auth'])->name('yabs.compare-choose'); + +Route::get('yabs-compare/{yabs1}/{yabs2}', 'App\Http\Controllers\YabsController@compareYabs')->middleware(['auth'])->name('yabs.compare'); + Route::get('servers-compare-choose', 'App\Http\Controllers\ServerController@chooseCompare')->middleware(['auth'])->name('servers-compare-choose'); Route::get('servers-compare/{server1}/{server2}', 'App\Http\Controllers\ServerController@compareServers')->middleware(['auth']);