Skip to content

Commit

Permalink
Inject queries directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jessarcher committed Oct 6, 2023
1 parent 4b53151 commit 563747e
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 34 deletions.
4 changes: 3 additions & 1 deletion src/Livewire/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Laravel\Pulse\Livewire\Concerns\HasPeriod;
use Laravel\Pulse\Livewire\Concerns\RemembersQueries;
use Laravel\Pulse\Livewire\Concerns\ShouldNotReportUsage;
use Laravel\Pulse\Queries\CacheInteractions;
use Laravel\Pulse\Queries\MonitoredCacheInteractions;
use Livewire\Attributes\Lazy;

#[Lazy]
Expand All @@ -18,7 +20,7 @@ class Cache extends Card
/**
* Render the component.
*/
public function render(callable $cacheInteractionsQuery, callable $monitoredCacheInteractionsQuery): Renderable
public function render(CacheInteractions $cacheInteractionsQuery, MonitoredCacheInteractions $monitoredCacheInteractionsQuery): Renderable
{
$monitoring = collect(Config::get('pulse.cache_keys'))
->mapWithKeys(fn (string $value, int|string $key) => is_string($key)
Expand Down
3 changes: 2 additions & 1 deletion src/Livewire/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laravel\Pulse\Livewire\Concerns\HasPeriod;
use Laravel\Pulse\Livewire\Concerns\RemembersQueries;
use Laravel\Pulse\Livewire\Concerns\ShouldNotReportUsage;
use Laravel\Pulse\Queries\Exceptions as ExceptionsQuery;
use Livewire\Attributes\Lazy;
use Livewire\Attributes\Url;

Expand All @@ -26,7 +27,7 @@ class Exceptions extends Card
/**
* Render the component.
*/
public function render(callable $query): Renderable
public function render(ExceptionsQuery $query): Renderable
{
$orderBy = match ($this->orderBy) {
'last_occurrence' => 'last_occurrence',
Expand Down
3 changes: 2 additions & 1 deletion src/Livewire/Queues.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\View;
use Laravel\Pulse\Livewire\Concerns\ShouldNotReportUsage;
use Laravel\Pulse\Queries\Queues as QueuesQuery;
use Livewire\Attributes\Lazy;

#[Lazy]
Expand All @@ -16,7 +17,7 @@ class Queues extends Card
/**
* Render the component.
*/
public function render(callable $query): Renderable
public function render(QueuesQuery $query): Renderable
{
return View::make('pulse::livewire.queues', [
'queues' => $queues = Cache::remember('laravel:pulse:queues:live', 5, fn () => $query()),
Expand Down
3 changes: 2 additions & 1 deletion src/Livewire/Servers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\View;
use Laravel\Pulse\Livewire\Concerns\HasPeriod;
use Laravel\Pulse\Livewire\Concerns\ShouldNotReportUsage;
use Laravel\Pulse\Queries\Servers as ServersQuery;
use Livewire\Attributes\Lazy;

#[Lazy]
Expand All @@ -16,7 +17,7 @@ class Servers extends Card
/**
* Render the component.
*/
public function render(callable $query): Renderable
public function render(ServersQuery $query): Renderable
{
$servers = $query($this->periodAsInterval());

Expand Down
3 changes: 2 additions & 1 deletion src/Livewire/SlowJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laravel\Pulse\Livewire\Concerns\HasPeriod;
use Laravel\Pulse\Livewire\Concerns\RemembersQueries;
use Laravel\Pulse\Livewire\Concerns\ShouldNotReportUsage;
use Laravel\Pulse\Queries\SlowJobs as SlowJobsQuery;
use Livewire\Attributes\Lazy;

#[Lazy]
Expand All @@ -17,7 +18,7 @@ class SlowJobs extends Card
/**
* Render the component.
*/
public function render(callable $query): Renderable
public function render(SlowJobsQuery $query): Renderable
{
[$slowJobs, $time, $runAt] = $this->remember($query);

Expand Down
3 changes: 2 additions & 1 deletion src/Livewire/SlowOutgoingRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laravel\Pulse\Livewire\Concerns\HasPeriod;
use Laravel\Pulse\Livewire\Concerns\RemembersQueries;
use Laravel\Pulse\Livewire\Concerns\ShouldNotReportUsage;
use Laravel\Pulse\Queries\SlowOutgoingRequests as SlowOutgoingRequestsQuery;
use Livewire\Attributes\Lazy;

#[Lazy]
Expand All @@ -18,7 +19,7 @@ class SlowOutgoingRequests extends Card
/**
* Render the component.
*/
public function render(callable $query): Renderable
public function render(SlowOutgoingRequestsQuery $query): Renderable
{
[$slowOutgoingRequests, $time, $runAt] = $this->remember($query);

Expand Down
3 changes: 2 additions & 1 deletion src/Livewire/SlowQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laravel\Pulse\Livewire\Concerns\HasPeriod;
use Laravel\Pulse\Livewire\Concerns\RemembersQueries;
use Laravel\Pulse\Livewire\Concerns\ShouldNotReportUsage;
use Laravel\Pulse\Queries\SlowQueries as SlowQueriesQuery;
use Livewire\Attributes\Lazy;

#[Lazy]
Expand All @@ -17,7 +18,7 @@ class SlowQueries extends Card
/**
* Render the component.
*/
public function render(callable $query): Renderable
public function render(SlowQueriesQuery $query): Renderable
{
[$slowQueries, $time, $runAt] = $this->remember($query);

Expand Down
3 changes: 2 additions & 1 deletion src/Livewire/SlowRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laravel\Pulse\Livewire\Concerns\HasPeriod;
use Laravel\Pulse\Livewire\Concerns\RemembersQueries;
use Laravel\Pulse\Livewire\Concerns\ShouldNotReportUsage;
use Laravel\Pulse\Queries\SlowRoutes as SlowRoutesQuery;
use Livewire\Attributes\Lazy;

#[Lazy]
Expand All @@ -17,7 +18,7 @@ class SlowRoutes extends Card
/**
* Render the component.
*/
public function render(callable $query): Renderable
public function render(SlowRoutesQuery $query): Renderable
{
[$slowRoutes, $time, $runAt] = $this->remember($query);

Expand Down
3 changes: 2 additions & 1 deletion src/Livewire/Usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laravel\Pulse\Livewire\Concerns\HasPeriod;
use Laravel\Pulse\Livewire\Concerns\RemembersQueries;
use Laravel\Pulse\Livewire\Concerns\ShouldNotReportUsage;
use Laravel\Pulse\Queries\Usage as UsageQuery;
use Livewire\Attributes\Lazy;
use Livewire\Attributes\Url;

Expand All @@ -33,7 +34,7 @@ class Usage extends Card
/**
* Render the component.
*/
public function render(callable $query): Renderable
public function render(UsageQuery $query): Renderable
{
$type = $this->type ?? $this->usage;

Expand Down
25 changes: 0 additions & 25 deletions src/PulseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function register(): void
$this->app->bind(Storage::class, DatabaseStorage::class);

$this->registerIngest();
$this->registerComponentMethodBindings();
}

/**
Expand All @@ -69,30 +68,6 @@ protected function registerIngest(): void
});
}

/**
* Register the Livewire component method bindings.
*/
protected function registerComponentMethodBindings(): void
{
foreach ([
Livewire\Usage::class => [Queries\Usage::class],
Livewire\Queues::class => [Queries\Queues::class],
Livewire\Servers::class => [Queries\Servers::class],
Livewire\SlowJobs::class => [Queries\SlowJobs::class],
Livewire\Exceptions::class => [Queries\Exceptions::class],
Livewire\SlowRoutes::class => [Queries\SlowRoutes::class],
Livewire\SlowQueries::class => [Queries\SlowQueries::class],
Livewire\SlowOutgoingRequests::class => [Queries\SlowOutgoingRequests::class],
Livewire\Cache::class => [Queries\CacheInteractions::class, Queries\MonitoredCacheInteractions::class],
] as $card => $queries) {
$this->app->bindMethod(
[$card, 'render'],
fn (Component $instance, Application $app) =>
$instance->render(...array_map($app->make(...), $queries))
);
}
}

/**
* Bootstrap any package services.
*/
Expand Down

0 comments on commit 563747e

Please sign in to comment.