Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jan 4, 2024
1 parent 9548631 commit 28a91f7
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/Livewire/OhDearUptimePulseCardComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ public function mount(?int $siteId = null)

$this->siteId = $siteId ?? config('services.oh_dear.pulse.site_id');

$this->setPerformanceRecords();
$this->setMaxPerformanceRecord();
$this->fetchPerformanceRecords();
}

public function setPerformanceRecords()
public function fetchPerformanceRecords(): void
{
$performanceRecords = $this->ohDear()->performanceRecords(
$this->siteId,
Carbon::now()->subMinutes(20),
Carbon::now(),
$performanceRecords = $this->rememberApiCall(
fn() => $this->ohDear()->performanceRecords(
$this->siteId,
Carbon::now()->subMinutes(20),
Carbon::now(),
),
'performance-records:'.$this->siteId,
CarbonInterval::seconds(30),
);

$performanceRecords = collect($performanceRecords)
Expand All @@ -64,13 +67,9 @@ public function setPerformanceRecords()
})->reverse()->values()->toArray();

$this->performanceRecords = $performanceRecords;
}

public function setMaxPerformanceRecord(): void
{
$this->maxPerformanceRecord = (int) ceil(collect($this->performanceRecords)
->max(fn (array $dataPoint) => $dataPoint[1])) + 10;

->max(fn (array $dataPoint) => $dataPoint[1])) + 10;
}

protected function getLabels(): array
Expand Down

0 comments on commit 28a91f7

Please sign in to comment.