mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
Fix query
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Services\Search;
|
||||
|
||||
use App\Services\Search\Support\ReleaseIndexProjection;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class ReleaseIndexProjectionTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function release_population_projection_avoids_a_wide_group_and_sort(): void
|
||||
{
|
||||
$sql = strtolower(ReleaseIndexProjection::query()->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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user