Files
UNIT3D-Community-Edition/app/Http/Livewire/NoteSearch.php
Roardom b6b4313bdc update: various database performance improvements
Use eager loading where necessary and add a few indexes. The existing index on private_messages for sender_id and read was probably a typo and intended for receiver_id. The first 3 tables indexes are added to are used for queries ran on every page load: namely the new pm, new notification and warnings indicator in the navbar. Additionally, another index on genre_movie proved useful for finding all the genres when given a movie id. Perhaps, another index for finding all movies within a genre would be good as well, but will leave that for a future optimization if deemed necessary.
2023-07-17 00:21:08 +00:00

49 lines
1.2 KiB
PHP

<?php
namespace App\Http\Livewire;
use App\Models\Note;
use Livewire\Component;
use Livewire\WithPagination;
class NoteSearch extends Component
{
use WithPagination;
public int $perPage = 25;
public string $search = '';
protected $queryString = [
'search' => ['except' => ''],
'page' => ['except' => 1],
'perPage' => ['except' => ''],
];
final public function updatedPage(): void
{
$this->emit('paginationChanged');
}
final public function updatingSearch(): void
{
$this->resetPage();
}
final public function getNotesProperty(): \Illuminate\Contracts\Pagination\LengthAwarePaginator
{
return Note::query()
->with(['noteduser.group', 'staffuser.group'])
->when($this->search, fn ($query) => $query->where('message', 'LIKE', '%'.$this->search.'%'))
->latest()
->paginate($this->perPage);
}
final public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Contracts\Foundation\Application
{
return view('livewire.note-search', [
'notes' => $this->notes,
]);
}
}