From 564e33c03f29f057f63ab74b9c2a4b8852627bd5 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:28:22 +0800 Subject: [PATCH] refactor(telescope): rename chunkSize property to chunk Rename DatabaseEntriesRepository::$chunkSize property to $chunk for better consistency with configuration key naming. --- .../src/Storage/DatabaseEntriesRepository.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/telescope/src/Storage/DatabaseEntriesRepository.php b/src/telescope/src/Storage/DatabaseEntriesRepository.php index fc7f83d07..dd1cf783c 100644 --- a/src/telescope/src/Storage/DatabaseEntriesRepository.php +++ b/src/telescope/src/Storage/DatabaseEntriesRepository.php @@ -38,10 +38,10 @@ class DatabaseEntriesRepository implements EntriesRepository, ClearableRepositor public function __construct( protected ?string $connection = null, - protected ?int $chunkSize = null + protected ?int $chunk = null ) { $this->connection ??= (string) config('telescope.storage.database.connection', 'default'); - $this->chunkSize ??= (int) config('telescope.storage.dateabase.chunk', 200); + $this->chunk ??= (int) config('telescope.storage.dateabase.chunk', 200); } public function find($id): EntryResult @@ -97,14 +97,14 @@ public function prune(DateTimeInterface $before, bool $keepExceptions): int $deleted = $this->table('telescope_entries') ->where('created_at', '<', $before) ->when($keepExceptions, fn ($query) => $query->where('type', '!=', 'exception')) - ->take($this->chunkSize) + ->take($this->chunk) ->delete(); $totalDeleted += $deleted; } while ($deleted !== 0); do { $deleted = $this->table('telescope_monitoring') - ->take($this->chunkSize) + ->take($this->chunk) ->delete(); } while ($deleted !== 0); @@ -125,7 +125,7 @@ public function store($entries): void $table = $this->table('telescope_entries'); - $entries->chunk($this->chunkSize)->each(function ($chunked) use ($table) { + $entries->chunk($this->chunk)->each(function ($chunked) use ($table) { $table->insert($chunked->map(function ($entry) { // @phpstan-ignore-line $entry->content = json_encode($entry->content, JSON_INVALID_UTF8_SUBSTITUTE); @@ -204,13 +204,13 @@ public function terminate(): void public function clear(): void { do { - $deleted = $this->table('telescope_entries')->take($this->chunkSize)->delete(); + $deleted = $this->table('telescope_entries')->take($this->chunk)->delete(); } while ($deleted !== 0); do { - $deleted = $this->table('telescope_entries_tags')->take($this->chunkSize)->delete(); + $deleted = $this->table('telescope_entries_tags')->take($this->chunk)->delete(); } while ($deleted !== 0); do { - $deleted = $this->table('telescope_monitoring')->take($this->chunkSize)->delete(); + $deleted = $this->table('telescope_monitoring')->take($this->chunk)->delete(); } while ($deleted !== 0); } @@ -286,7 +286,7 @@ protected function updateTags($entry) */ protected function storeExceptions(Collection $exceptions) { - $exceptions->chunk($this->chunkSize)->each(function ($chunked) { + $exceptions->chunk($this->chunk)->each(function ($chunked) { $this->table('telescope_entries')->insert($chunked->map(function ($exception) { $occurrences = $this->countExceptionOccurences($exception); @@ -313,7 +313,7 @@ protected function storeExceptions(Collection $exceptions) */ protected function storeTags(Collection $results) { - $results->chunk($this->chunkSize)->each(function ($chunked) { + $results->chunk($this->chunk)->each(function ($chunked) { try { $this->table('telescope_entries_tags') ->insert($chunked->flatMap(