Skip to content

Commit 3674ed5

Browse files
committed
No need to add queries if there is no author field
1 parent 1439cdc commit 3674ed5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Http/Controllers/CP/Collections/QueriesAuthorEntries.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ protected function queryAuthorEntries(Builder $query, Collection $collection): v
1515
$blueprintsWithAuthor = $this->blueprintsWithAuthor($collection->entryBlueprints());
1616
$blueprintsWithoutAuthor = $this->blueprintsWithoutAuthor($collection->entryBlueprints());
1717

18+
if (empty($blueprintsWithAuthor)) {
19+
return;
20+
}
21+
1822
$query->where(fn ($query) => $query
1923
->whereNotIn('collectionHandle', [$collection->handle()]) // Needed for entries fieldtypes configured for multiple collections
20-
->when($blueprintsWithAuthor, fn ($query) => $query
21-
->orWhere(fn ($query) => $query
22-
->whereIn('blueprint', $blueprintsWithAuthor)
23-
->whereHas('author', fn ($subquery) => $subquery->where('id', User::current()->id()))
24-
)
24+
->orWhere(fn ($query) => $query
25+
->whereIn('blueprint', $blueprintsWithAuthor)
26+
->whereHas('author', fn ($subquery) => $subquery->where('id', User::current()->id()))
2527
)
2628
->orWhereIn('blueprint', $blueprintsWithoutAuthor)
2729
);

0 commit comments

Comments
 (0)