Skip to content

Commit

Permalink
refactor(telescope): rename chunkSize property to chunk
Browse files Browse the repository at this point in the history
Rename DatabaseEntriesRepository::$chunkSize property to $chunk for
better consistency with configuration key naming.
  • Loading branch information
huangdijia committed Dec 11, 2024
1 parent 4d92d7d commit 564e33c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/telescope/src/Storage/DatabaseEntriesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand All @@ -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(
Expand Down

0 comments on commit 564e33c

Please sign in to comment.