From 0be8793adcdbc8bd22ad06bf714aa4ba33584c4e Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 10 Sep 2025 10:35:12 +0100 Subject: [PATCH 1/3] Fix speed regression on model status query by going through eloquent model --- src/Entries/EntryQueryBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entries/EntryQueryBuilder.php b/src/Entries/EntryQueryBuilder.php index fcf9e016..2310f3b1 100644 --- a/src/Entries/EntryQueryBuilder.php +++ b/src/Entries/EntryQueryBuilder.php @@ -145,7 +145,7 @@ private function ensureCollectionsAreQueriedForStatusQuery(): void // If no IDs were queried, fall back to all collections. $ids->isEmpty() ? $this->whereIn('collection', Collection::handles()) - : $this->whereIn('collection', app(static::class)->whereIn('id', $ids)->pluck('collection')->map(fn ($collection) => $collection?->handle)->filter()->unique()->values()); + : $this->whereIn('collection', app('statamic.eloquent.entries.model')::query()->whereIn('id', $ids)->distinct('collection')->pluck('collection')->values()); } private function getCollectionsForStatusQuery(): \Illuminate\Support\Collection From b07af45529fb79440ec12a58b6a71ae41c83dc29 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 10 Sep 2025 15:48:02 +0100 Subject: [PATCH 2/3] When we're plucking id, go for speed --- src/Entries/EntryQueryBuilder.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Entries/EntryQueryBuilder.php b/src/Entries/EntryQueryBuilder.php index 2310f3b1..6b3fedcc 100644 --- a/src/Entries/EntryQueryBuilder.php +++ b/src/Entries/EntryQueryBuilder.php @@ -233,4 +233,13 @@ protected function getJsonCasts(): IlluminateCollection }) ->filter(); } + + public function pluck($column, $key = null) + { + if (! $key && ($column == 'id')) { + return $this->builder->pluck('id'); + } + + return parent::pluck($column, $key); + } } From 75a05fa449fd20ed4350a63d12face22899fa8e4 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Thu, 11 Sep 2025 09:08:34 +0100 Subject: [PATCH 3/3] Abstract out blink column cache --- src/Entries/EntryQueryBuilder.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Entries/EntryQueryBuilder.php b/src/Entries/EntryQueryBuilder.php index 6b3fedcc..316b01b5 100644 --- a/src/Entries/EntryQueryBuilder.php +++ b/src/Entries/EntryQueryBuilder.php @@ -55,9 +55,7 @@ protected function column($column) $column = 'origin_id'; } - $columns = Blink::once('eloquent-entry-data-column-mappings', fn () => array_merge(self::COLUMNS, (new EloquentEntry)->getDataColumnMappings($this->builder->getModel()))); - - if (! in_array($column, $columns)) { + if (! in_array($column, $this->entryColumnsAndMappings())) { if (! Str::startsWith($column, 'data->')) { $column = 'data->'.$column; } @@ -236,10 +234,15 @@ protected function getJsonCasts(): IlluminateCollection public function pluck($column, $key = null) { - if (! $key && ($column == 'id')) { - return $this->builder->pluck('id'); + if (! $key && in_array($column, $this->entryColumnsAndMappings())) { + return $this->builder->pluck($column, $key); } return parent::pluck($column, $key); } + + private function entryColumnsAndMappings() + { + return Blink::once('eloquent-entry-data-column-mappings', fn () => array_merge(self::COLUMNS, (new EloquentEntry)->getDataColumnMappings($this->builder->getModel()))); + } }