-
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '5.x' of github.com:Power-Components/livewire-powergrid …
…into 5.x
- Loading branch information
Showing
9 changed files
with
100 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace PowerComponents\LivewirePowerGrid\Events; | ||
|
||
class PowerGridPerformanceData | ||
{ | ||
/** | ||
* @param string $tableName Name of the table where the data was retrieved. | ||
* @param float $retrieveDataInMs Total time spent on the data retrieval operation. | ||
* @param float $queriesTimeInMs Total time spent on executing queries. | ||
* @param bool $isCached | ||
* @param array $queries List of queries executed (query, binding, time). | ||
*/ | ||
public function __construct( | ||
public string $tableName, | ||
public float $retrieveDataInMs, | ||
public float $queriesTimeInMs = 0, | ||
public bool $isCached = false, | ||
public array $queries = [], | ||
) { | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace PowerComponents\LivewirePowerGrid\Livewire; | ||
|
||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Support\Facades\Config; | ||
use Livewire\Attributes\Lazy; | ||
use PowerComponents\LivewirePowerGrid\Recorders\PowerGridPerformanceRecorder; | ||
|
||
#[Lazy] | ||
class PerformanceCard extends \Laravel\Pulse\Livewire\Card | ||
{ | ||
public function render(): View | ||
{ | ||
$config = Config::get('pulse.recorders.' . PowerGridPerformanceRecorder::class); | ||
|
||
$averageRetrieveData = 0; | ||
$averageQueriesTime = 0; | ||
$records = collect(); | ||
|
||
if (data_get($config, 'enabled')) { | ||
$records = \Laravel\Pulse\Facades\Pulse::values('powergrid-performance') | ||
->map(function ($item) { | ||
/** @var array $value */ | ||
$value = json_decode($item->value, true); | ||
$item->tableName = $value['tableName']; | ||
$item->retrieveDataInMs = $value['retrieveDataInMs']; | ||
$item->queriesTimeInMs = $value['queriesTimeInMs']; | ||
$item->isCached = $value['isCached']; | ||
$item->queries = $value['queries']; | ||
unset($item->value); | ||
|
||
return $item; | ||
}) | ||
->sort(fn ($a, $b) => $b->timestamp <=> $a->timestamp) | ||
->take(10) | ||
->values(); | ||
|
||
$averageRetrieveData = $records->avg(fn ($item) => $item->retrieveDataInMs); | ||
$averageQueriesTime = $records->avg(fn ($item) => $item->queriesTimeInMs); | ||
} | ||
|
||
return view( | ||
'livewire-powergrid::livewire.performance-card', | ||
compact( | ||
'records', | ||
'averageQueriesTime', | ||
'averageRetrieveData', | ||
'config' | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters