optimize: whereIn and whereNotIn queries

This commit is contained in:
HDVinnie
2022-01-10 16:25:26 -05:00
parent d601775e7e
commit 5e01a26c88
16 changed files with 52 additions and 52 deletions
+2 -2
View File
@@ -54,9 +54,9 @@ class SubtitleSearch extends Component
return Subtitle::with(['user', 'torrent', 'language'])
->when($this->search, fn ($query) => $query->where('title', 'like', '%'.$this->search.'%'))
->when($this->categories, function ($query) {
$torrents = Torrent::whereIn('category_id', $this->categories)->pluck('id');
$torrents = Torrent::whereIntegerInRaw('category_id', $this->categories)->pluck('id');
return $query->whereIn('torrent_id', $torrents);
return $query->whereIntegerInRaw('torrent_id', $torrents);
})
->when($this->language, fn ($query) => $query->where('language_id', '=', $this->language))
->orderBy($this->sortField, $this->sortDirection)