Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Provide searchable entries and terms lazily #9171

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Search/ProvidesSearchables.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Search;

use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;

interface ProvidesSearchables
{
Expand All @@ -12,7 +13,7 @@ public static function referencePrefix(): string;

public function setKeys(array $keys): self;

public function provide(): Collection;
public function provide(): Collection|LazyCollection;

public function contains($searchable): bool;

Expand Down
5 changes: 3 additions & 2 deletions src/Search/Searchables/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Search\Searchables;

use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use Statamic\Contracts\Entries\Entry as EntryContract;
use Statamic\Facades\Entry;

Expand All @@ -18,7 +19,7 @@ public static function referencePrefix(): string
return 'entry';
}

public function provide(): Collection
public function provide(): Collection|LazyCollection
{
$query = Entry::query();

Expand All @@ -30,7 +31,7 @@ public function provide(): Collection
$query->where('site', $site);
}

return $query->get()->filter($this->filter())->values();
return $query->lazy(100)->filter($this->filter())->values();
}

public function contains($searchable): bool
Expand Down
5 changes: 3 additions & 2 deletions src/Search/Searchables/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Search\Searchables;

use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use Statamic\Contracts\Taxonomies\Term as TermContract;
use Statamic\Facades\Term;
use Statamic\Support\Str;
Expand All @@ -19,7 +20,7 @@ public static function referencePrefix(): string
return 'term';
}

public function provide(): Collection
public function provide(): Collection|LazyCollection
{
$query = Term::query();

Expand All @@ -31,7 +32,7 @@ public function provide(): Collection
$query->where('site', $site);
}

return $query->get()->filter($this->filter())->values();
return $query->lazy(100)->filter($this->filter())->values();
}

public function contains($searchable): bool
Expand Down
Loading