From a6a095586fb192cfd3b3ee6565efa8d5affe9538 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 8 May 2026 18:52:14 +0200 Subject: [PATCH] Remove nzb_guid column --- app/Models/ReleaseComment.php | 2 - app/Services/Nzb/NzbImportService.php | 31 ------ app/Services/Nzb/NzbService.php | 8 -- ...026_05_08_180000_drop_nzb_guid_columns.php | 100 ++++++++++++++++++ tests/Feature/CbpCleanupServiceTest.php | 5 +- .../ReleaseNameFixedRecategorizationTest.php | 4 - 6 files changed, 101 insertions(+), 49 deletions(-) create mode 100644 database/migrations/2026_05_08_180000_drop_nzb_guid_columns.php diff --git a/app/Models/ReleaseComment.php b/app/Models/ReleaseComment.php index d9a763f0c..edbfdbe25 100644 --- a/app/Models/ReleaseComment.php +++ b/app/Models/ReleaseComment.php @@ -29,7 +29,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; * @property string $shareid * @property string $siteid * @property int|null $sourceid - * @property mixed $nzb_guid * @property-read Release $release * @property-read User $user * @@ -40,7 +39,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ReleaseComment whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ReleaseComment whereIssynced($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ReleaseComment whereIsvisible($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ReleaseComment whereNzbGuid($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ReleaseComment whereReleasesId($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ReleaseComment whereShared($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ReleaseComment whereShareid($value) diff --git a/app/Services/Nzb/NzbImportService.php b/app/Services/Nzb/NzbImportService.php index c0e4fcf5a..426e80046 100644 --- a/app/Services/Nzb/NzbImportService.php +++ b/app/Services/Nzb/NzbImportService.php @@ -57,11 +57,6 @@ class NzbImportService public NzbService $nzb; - /** - * The MD5 hash of the first segment Message-ID of the NZB - */ - protected string $nzbGuid; - /** * @param array $options */ @@ -123,8 +118,6 @@ class NzbImportService // Loop over the NZB file names only. foreach ($nzbFiles as $nzbFilePath) { - $this->nzbGuid = ''; - // Check if the file is really there. if (File::isFile($nzbFilePath)) { // Get the contents of the NZB file as a string. @@ -187,7 +180,6 @@ class NzbImportService } $nzbsSkipped++; } else { - $this->updateNzbGuid(); if ($delete) { // Remove the nzb file. File::delete($nzbFilePath); @@ -339,17 +331,6 @@ class NzbImportService // After scanning all files, persist any matched whitelist/blacklist usage $this->blacklistService->updateBlacklistUsage($this->blacklistService->getAndClearIdsToUpdate()); // @phpstan-ignore argument.type - // Sort values alphabetically but keep the keys intact - if (\count($binary_names) > 0) { - asort($binary_names); - foreach ($nzbXML->file as $file) { - if ($file['subject'] === $binary_names[0]) { - $this->nzbGuid = md5((string) $file->segments->segment); - break; - } - } - } - // Try to insert the NZB details into the DB. return $this->insertNZB( [ @@ -469,16 +450,4 @@ class NzbImportService cli()->notice($message); } } - - /** - * The function updates the NZB guid after there is no chance of deletion. - */ - protected function updateNzbGuid(): void - { - try { - Release::query()->where('guid', $this->relGuid)->update(['nzb_guid' => sodium_hex2bin($this->nzbGuid)]); - } catch (\SodiumException $e) { - $this->echoOut('ERROR: Problem updating nzb_guid for: '.$this->relGuid); - } - } } diff --git a/app/Services/Nzb/NzbService.php b/app/Services/Nzb/NzbService.php index 8689e1031..9b1cb6d4b 100644 --- a/app/Services/Nzb/NzbService.php +++ b/app/Services/Nzb/NzbService.php @@ -124,8 +124,6 @@ class NzbService $XMLWriter->setIndent(true); $XMLWriter->setIndentString(' '); - $nzb_guid = ''; - $XMLWriter->startDocument('1.0', 'UTF-8'); $XMLWriter->startDtd(self::NZB_DTD_NAME, self::NZB_DTD_PUBLIC, self::NZB_DTD_EXTERNAL); $XMLWriter->endDtd(); @@ -181,9 +179,6 @@ class NzbService $XMLWriter->startElement('segments'); foreach ($parts as $part) { $messageId = $this->normalizeSegmentMessageId($part->messageid); - if ($nzb_guid === '') { - $nzb_guid = $messageId; - } $XMLWriter->startElement('segment'); $XMLWriter->writeAttribute('bytes', (string) $part->size); $XMLWriter->writeAttribute('number', (string) $part->partnumber); @@ -212,9 +207,6 @@ class NzbService } // Mark release as having NZB. $release->update(['nzbstatus' => self::NZB_ADDED]); - if (! empty($nzb_guid)) { - $release->update(['nzb_guid' => DB::raw('UNHEX( '.escapeString(md5((string) $nzb_guid)).' )')]); - } // Delete CBP (Collections, Binaries, Parts) for release that has its NZB created. // Use a transaction to ensure cascading deletes complete properly. diff --git a/database/migrations/2026_05_08_180000_drop_nzb_guid_columns.php b/database/migrations/2026_05_08_180000_drop_nzb_guid_columns.php new file mode 100644 index 000000000..d4dce2893 --- /dev/null +++ b/database/migrations/2026_05_08_180000_drop_nzb_guid_columns.php @@ -0,0 +1,100 @@ +indexExists('releases', 'ix_releases_nzb_guid')) { + Schema::table('releases', function (Blueprint $table) { + $table->dropIndex('ix_releases_nzb_guid'); + }); + } + + if (Schema::hasTable('releases') && Schema::hasColumn('releases', 'nzb_guid')) { + Schema::table('releases', function (Blueprint $table) { + $table->dropColumn('nzb_guid'); + }); + } + + if (Schema::hasTable('release_comments') && Schema::hasColumn('release_comments', 'nzb_guid')) { + Schema::table('release_comments', function (Blueprint $table) { + $table->dropColumn('nzb_guid'); + }); + } + } + + public function down(): void + { + $driver = DB::getDriverName(); + + if (Schema::hasTable('releases') && ! Schema::hasColumn('releases', 'nzb_guid')) { + if ($driver === 'sqlite') { + Schema::table('releases', function (Blueprint $table) { + $table->binary('nzb_guid')->nullable(); + }); + } else { + DB::statement( + "ALTER TABLE `releases` ADD COLUMN `nzb_guid` BLOB NOT NULL DEFAULT ''" + ); + } + } + + if (Schema::hasTable('releases') && ! $this->indexExists('releases', 'ix_releases_nzb_guid')) { + if ($driver === 'sqlite') { + Schema::table('releases', function (Blueprint $table) { + $table->index('nzb_guid', 'ix_releases_nzb_guid'); + }); + } else { + DB::statement('CREATE INDEX `ix_releases_nzb_guid` ON `releases` (`nzb_guid`(3072))'); + } + } + + if (Schema::hasTable('release_comments') && ! Schema::hasColumn('release_comments', 'nzb_guid')) { + if ($driver === 'sqlite') { + Schema::table('release_comments', function (Blueprint $table) { + $table->binary('nzb_guid')->nullable(); + }); + } else { + DB::statement( + "ALTER TABLE `release_comments` ADD COLUMN `nzb_guid` BINARY(16) NOT NULL DEFAULT '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0'" + ); + } + } + } + + private function indexExists(string $table, string $indexName): bool + { + if (DB::getDriverName() === 'sqlite') { + $rows = DB::select( + "SELECT name FROM sqlite_master WHERE type = 'index' AND tbl_name = ? AND name = ?", + [$table, $indexName] + ); + + return $rows !== []; + } + + $rows = DB::select("SHOW INDEX FROM `{$table}` WHERE Key_name = ?", [$indexName]); + + return $rows !== []; + } +}; diff --git a/tests/Feature/CbpCleanupServiceTest.php b/tests/Feature/CbpCleanupServiceTest.php index 1521157db..4950bbaeb 100644 --- a/tests/Feature/CbpCleanupServiceTest.php +++ b/tests/Feature/CbpCleanupServiceTest.php @@ -89,7 +89,6 @@ class CbpCleanupServiceTest extends TestCase 'iscategorized' => 1, 'predb_id' => 0, 'source' => null, - 'nzb_guid' => null, ]); DB::table('collections')->insert([ @@ -158,7 +157,6 @@ class CbpCleanupServiceTest extends TestCase 'iscategorized' => 1, 'predb_id' => 0, 'source' => null, - 'nzb_guid' => null, ]); DB::table('collections')->insert([ @@ -244,8 +242,7 @@ class CbpCleanupServiceTest extends TestCase isrenamed INTEGER, iscategorized INTEGER, predb_id INTEGER, - source VARCHAR(255) NULL, - nzb_guid BLOB NULL + source VARCHAR(255) NULL )'); DB::statement('CREATE TABLE collections ( id INTEGER PRIMARY KEY, diff --git a/tests/Feature/ReleaseNameFixedRecategorizationTest.php b/tests/Feature/ReleaseNameFixedRecategorizationTest.php index 45b3623df..5df4044b1 100644 --- a/tests/Feature/ReleaseNameFixedRecategorizationTest.php +++ b/tests/Feature/ReleaseNameFixedRecategorizationTest.php @@ -106,7 +106,6 @@ class ReleaseNameFixedRecategorizationTest extends TestCase 'isrenamed' => 0, 'guid' => str_repeat('a', 40), 'leftguid' => 'a', - 'nzb_guid' => 'test', 'size' => 1, 'postdate' => now(), 'adddate' => now(), @@ -154,7 +153,6 @@ class ReleaseNameFixedRecategorizationTest extends TestCase 'isrenamed' => 0, 'guid' => str_repeat('b', 40), 'leftguid' => 'b', - 'nzb_guid' => 'test-olympics', 'size' => 1, 'postdate' => now(), 'adddate' => now(), @@ -200,7 +198,6 @@ class ReleaseNameFixedRecategorizationTest extends TestCase 'isrenamed' => 1, 'guid' => str_repeat('c', 40), 'leftguid' => 'c', - 'nzb_guid' => 'test-southern-charm', 'size' => 1, 'postdate' => now(), 'adddate' => now(), @@ -298,7 +295,6 @@ class ReleaseNameFixedRecategorizationTest extends TestCase $table->tinyInteger('proc_crc32')->default(0); $table->tinyInteger('passwordstatus')->default(0); $table->tinyInteger('nzbstatus')->default(0); - $table->binary('nzb_guid')->nullable(); }); } }