diff --git a/app/Console/Commands/NntmuxPopulateSearchIndexes.php b/app/Console/Commands/NntmuxPopulateSearchIndexes.php index 70d563d9e..ea60768c8 100644 --- a/app/Console/Commands/NntmuxPopulateSearchIndexes.php +++ b/app/Console/Commands/NntmuxPopulateSearchIndexes.php @@ -170,11 +170,10 @@ class NntmuxPopulateSearchIndexes extends Command return Command::SUCCESS; } + // Optimized query: avoid GROUP_CONCAT and complex joins for faster population + // External media IDs can be populated separately if needed $query = Release::query() ->orderByDesc('releases.id') - ->leftJoin('release_files', 'releases.id', '=', 'release_files.releases_id') - ->leftJoin('movieinfo', 'releases.movieinfo_id', '=', 'movieinfo.id') - ->leftJoin('videos', 'releases.videos_id', '=', 'videos.id') ->select([ 'releases.id', 'releases.name', @@ -183,36 +182,7 @@ class NntmuxPopulateSearchIndexes extends Command 'releases.categories_id', 'releases.videos_id', 'releases.movieinfo_id', - // Movie external IDs - 'movieinfo.imdbid', - 'movieinfo.tmdbid', - 'movieinfo.traktid', - // TV show external IDs - 'videos.tvdb', - 'videos.tvmaze', - 'videos.tvrage', - DB::raw('videos.trakt as video_trakt'), - DB::raw('videos.imdb as video_imdb'), - DB::raw('videos.tmdb as video_tmdb'), - ]) - ->selectRaw('IFNULL(GROUP_CONCAT(release_files.name SEPARATOR " "),"") AS filename') - ->groupBy([ - 'releases.id', - 'releases.name', - 'releases.searchname', - 'releases.fromname', - 'releases.categories_id', - 'releases.videos_id', - 'releases.movieinfo_id', - 'movieinfo.imdbid', - 'movieinfo.tmdbid', - 'movieinfo.traktid', - 'videos.tvdb', - 'videos.tvmaze', - 'videos.tvrage', - 'videos.trakt', - 'videos.imdb', - 'videos.tmdb', + 'releases.imdbid', ]); return $this->processManticoreData( @@ -226,17 +196,15 @@ class NntmuxPopulateSearchIndexes extends Command 'searchname' => (string) ($item->searchname ?? ''), 'fromname' => (string) ($item->fromname ?? ''), 'categories_id' => (int) ($item->categories_id ?? 0), - 'filename' => (string) ($item->filename ?? ''), + 'filename' => '', 'videos_id' => (int) ($item->videos_id ?? 0), 'movieinfo_id' => (int) ($item->movieinfo_id ?? 0), - // Movie external IDs 'imdbid' => (int) ($item->imdbid ?? 0), - 'tmdbid' => (int) ($item->tmdbid ?? 0), - 'traktid' => (int) ($item->traktid ?? 0), - // TV show external IDs (use video_* for TV shows, fallback to movie IDs) - 'tvdb' => (int) ($item->tvdb ?? 0), - 'tvmaze' => (int) ($item->tvmaze ?? 0), - 'tvrage' => (int) ($item->tvrage ?? 0), + 'tmdbid' => 0, + 'traktid' => 0, + 'tvdb' => 0, + 'tvmaze' => 0, + 'tvrage' => 0, ]; } ); diff --git a/app/Services/Search/Drivers/ManticoreSearchDriver.php b/app/Services/Search/Drivers/ManticoreSearchDriver.php index 0471ee93d..f501c0a84 100644 --- a/app/Services/Search/Drivers/ManticoreSearchDriver.php +++ b/app/Services/Search/Drivers/ManticoreSearchDriver.php @@ -275,13 +275,9 @@ class ManticoreSearchDriver implements SearchDriverInterface return ['success' => 0, 'errors' => 0]; } - $success = 0; - $errors = 0; - $documents = []; foreach ($releases as $release) { if (empty($release['id'])) { - $errors++; continue; } @@ -292,7 +288,6 @@ class ManticoreSearchDriver implements SearchDriverInterface 'fromname' => (string) ($release['fromname'] ?? ''), 'categories_id' => (int) ($release['categories_id'] ?? 0), 'filename' => (string) ($release['filename'] ?? ''), - // External media IDs for efficient searching 'imdbid' => (int) ($release['imdbid'] ?? 0), 'tmdbid' => (int) ($release['tmdbid'] ?? 0), 'traktid' => (int) ($release['traktid'] ?? 0), @@ -304,26 +299,20 @@ class ManticoreSearchDriver implements SearchDriverInterface ]; } - if (! empty($documents)) { - try { - // Log first document for debugging if app.debug is enabled - if (config('app.debug') && ! empty($documents[0])) { - Log::debug('ManticoreSearch bulkInsertReleases sample document', [ - 'first_doc' => $documents[0], - 'total_docs' => count($documents), - ]); - } - - $this->manticoreSearch->table($this->config['indexes']['releases']) - ->replaceDocuments($documents); - $success = count($documents); - } catch (\Throwable $e) { - Log::error('ManticoreSearch bulkInsertReleases error: '.$e->getMessage()); - $errors += count($documents); - } + if (empty($documents)) { + return ['success' => 0, 'errors' => 0]; } - return ['success' => $success, 'errors' => $errors]; + try { + $this->manticoreSearch->table($this->config['indexes']['releases']) + ->replaceDocuments($documents); + + return ['success' => count($documents), 'errors' => 0]; + } catch (\Throwable $e) { + Log::error('ManticoreSearch bulkInsertReleases error: '.$e->getMessage()); + + return ['success' => 0, 'errors' => count($documents)]; + } } /** @@ -338,13 +327,9 @@ class ManticoreSearchDriver implements SearchDriverInterface return ['success' => 0, 'errors' => 0]; } - $success = 0; - $errors = 0; - $documents = []; foreach ($predbRecords as $predb) { if (empty($predb['id'])) { - $errors++; continue; } @@ -356,26 +341,20 @@ class ManticoreSearchDriver implements SearchDriverInterface ]; } - if (! empty($documents)) { - try { - // Log first document for debugging if app.debug is enabled - if (config('app.debug') && ! empty($documents[0])) { - Log::debug('ManticoreSearch bulkInsertPredb sample document', [ - 'first_doc' => $documents[0], - 'total_docs' => count($documents), - ]); - } - - $this->manticoreSearch->table($this->config['indexes']['predb']) - ->replaceDocuments($documents); - $success = count($documents); - } catch (\Throwable $e) { - Log::error('ManticoreSearch bulkInsertPredb error: '.$e->getMessage()); - $errors += count($documents); - } + if (empty($documents)) { + return ['success' => 0, 'errors' => 0]; } - return ['success' => $success, 'errors' => $errors]; + try { + $this->manticoreSearch->table($this->config['indexes']['predb']) + ->replaceDocuments($documents); + + return ['success' => count($documents), 'errors' => 0]; + } catch (\Throwable $e) { + Log::error('ManticoreSearch bulkInsertPredb error: '.$e->getMessage()); + + return ['success' => 0, 'errors' => count($documents)]; + } } /**