diff --git a/app/Console/Commands/NntmuxPopulateSearchIndexes.php b/app/Console/Commands/NntmuxPopulateSearchIndexes.php index 9153d8cb5..9152c7def 100644 --- a/app/Console/Commands/NntmuxPopulateSearchIndexes.php +++ b/app/Console/Commands/NntmuxPopulateSearchIndexes.php @@ -46,7 +46,7 @@ class NntmuxPopulateSearchIndexes extends Command {--steam : Populates the Steam apps index} {--anime : Populates the anime titles index} {--all : Populate all supported indexes for the selected engine} - {--count=50000 : Sets the chunk size} + {--count=5000 : Sets the database chunk size} {--parallel=4 : Number of parallel processes} {--batch-size=5000 : Batch size for bulk operations} {--disable-keys : Disable database keys during population} @@ -68,7 +68,7 @@ class NntmuxPopulateSearchIndexes extends Command private const GROUP_CONCAT_MAX_LEN = 16384; - private const DEFAULT_CHUNK_SIZE = 50000; + private const DEFAULT_CHUNK_SIZE = 5000; /** @phpstan-ignore classConstant.unused */ private const DEFAULT_PARALLEL_PROCESSES = 4; diff --git a/app/Services/Search/Support/ReleaseIndexProjection.php b/app/Services/Search/Support/ReleaseIndexProjection.php index 04eceb20a..08430e816 100644 --- a/app/Services/Search/Support/ReleaseIndexProjection.php +++ b/app/Services/Search/Support/ReleaseIndexProjection.php @@ -15,10 +15,11 @@ final class ReleaseIndexProjection { public static function query(): Builder { - $groupConcat = DB::connection()->getDriverName() === 'sqlite' - ? "GROUP_CONCAT(rf.name, ' ')" - : "GROUP_CONCAT(rf.name SEPARATOR ' ')"; - $categoryName = DB::connection()->getDriverName() === 'sqlite' + $isSqlite = DB::connection()->getDriverName() === 'sqlite'; + $filename = $isSqlite + ? "COALESCE((SELECT GROUP_CONCAT(rf.name, ' ') FROM release_files rf WHERE rf.releases_id = r.id), '')" + : "COALESCE((SELECT GROUP_CONCAT(rf.name SEPARATOR ' ') FROM release_files rf WHERE rf.releases_id = r.id), '')"; + $categoryName = $isSqlite ? "cp.title || ' > ' || c.title" : "CONCAT(cp.title, ' > ', c.title)"; @@ -38,7 +39,6 @@ final class ReleaseIndexProjection $join->on('tve.id', '=', 'r.tv_episodes_id') ->where('r.tv_episodes_id', '>', 0); }) - ->leftJoin('release_files as rf', 'rf.releases_id', '=', 'r.id') ->leftJoin('release_nfos as rn', 'rn.releases_id', '=', 'r.id') ->leftJoin('video_data as vd', 'vd.releases_id', '=', 'r.id') ->select([ @@ -50,7 +50,7 @@ final class ReleaseIndexProjection 'c.title as sub_category', 'tve.title as episode_title', 'tve.series', 'tve.episode', 'tve.firstaired', 'cp.title as parent_category', DB::raw("{$categoryName} AS category_name"), - DB::raw("COALESCE({$groupConcat}, '') AS filename"), + DB::raw("{$filename} AS filename"), DB::raw('COALESCE(mi.tmdbid, 0) AS tmdbid'), DB::raw('COALESCE(mi.traktid, 0) AS traktid'), DB::raw('COALESCE(v.tvdb, 0) AS tvdb'), @@ -61,16 +61,6 @@ final class ReleaseIndexProjection DB::raw('COALESCE(v.tmdb, 0) AS tmdb'), DB::raw('COALESCE(rn.releases_id, 0) AS nfoid'), DB::raw('COALESCE(vd.releases_id, 0) AS reid'), - ]) - ->groupBy([ - 'r.id', 'r.guid', 'r.name', 'r.searchname', 'r.fromname', 'r.categories_id', - 'r.groups_id', 'r.size', 'r.postdate', 'r.adddate', 'r.totalpart', 'r.grabs', - 'r.comments', 'r.passwordstatus', 'r.nzbstatus', 'r.nfostatus', 'r.haspreview', - 'r.jpgstatus', 'r.videos_id', 'r.tv_episodes_id', 'r.movieinfo_id', 'r.imdbid', - 'r.anidbid', 'g.name', 'c.root_categories_id', 'c.title', 'tve.title', - 'tve.series', 'tve.episode', 'tve.firstaired', 'cp.title', 'mi.tmdbid', - 'mi.traktid', 'v.tvdb', 'v.tvmaze', 'v.tvrage', 'v.trakt', 'v.imdb', 'v.tmdb', - 'rn.releases_id', 'vd.releases_id', ]); } diff --git a/tests/Unit/Services/Search/ReleaseIndexProjectionTest.php b/tests/Unit/Services/Search/ReleaseIndexProjectionTest.php new file mode 100644 index 000000000..187f80818 --- /dev/null +++ b/tests/Unit/Services/Search/ReleaseIndexProjectionTest.php @@ -0,0 +1,24 @@ +orderBy('r.id')->limit(5000)->toSql()); + + self::assertStringContainsString('select group_concat(rf.name', $sql); + self::assertStringContainsString('where rf.releases_id = r.id', $sql); + self::assertStringNotContainsString('join "release_files"', $sql); + self::assertStringNotContainsString(' group by ', $sql); + self::assertStringContainsString('order by "r"."id" asc limit 5000', $sql); + } +}