From 76da386abdcf7e1649ba426d6ab27d48d86d51f3 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 19 Mar 2019 13:44:50 +0100 Subject: [PATCH] Use query builder to fetch collections/binaries and parts when creating nzbs, drop initiateforwrite and setQueries functions --- Blacklight/NZB.php | 42 +++++------------------ Blacklight/processing/ProcessReleases.php | 2 -- Changelog | 1 + 3 files changed, 9 insertions(+), 36 deletions(-) diff --git a/Blacklight/NZB.php b/Blacklight/NZB.php index 6347b2f1a..7a9af56dd 100755 --- a/Blacklight/NZB.php +++ b/Blacklight/NZB.php @@ -2,6 +2,8 @@ namespace Blacklight; +use App\Models\Binary; +use App\Models\Part; use App\Models\Release; use App\Models\Settings; use App\Models\Collection; @@ -117,37 +119,6 @@ class NZB ); } - /** - * Initiate class vars when writing NZBs. - */ - public function initiateForWrite() - { - $this->setQueries(); - } - - /** - * Generate queries for collections, binaries and parts. - */ - protected function setQueries(): void - { - $this->_collectionsQuery = ' - SELECT c.*, UNIX_TIMESTAMP(c.date) AS udate, - g.name AS groupname - FROM collections c - INNER JOIN usenet_groups g ON c.groups_id = g.id - WHERE c.releases_id = '; - $this->_binariesQuery = ' - SELECT b.id, b.name, b.totalparts - FROM binaries b - WHERE b.collections_id = %d - ORDER BY b.name ASC'; - $this->_partsQuery = ' - SELECT DISTINCT(p.messageid), p.size, p.partnumber - FROM parts p - WHERE p.binaries_id = %d - ORDER BY p.partnumber ASC'; - } - /** * Write an NZB to the hard drive for a single release. * @@ -160,7 +131,10 @@ class NZB */ public function writeNzbForReleaseId(Release $release): bool { - $collections = DB::select($this->_collectionsQuery.$release->id); + $collections = Collection::whereReleasesId($release->id) + ->join('usenet_groups', 'collections.groups_id', '=', 'usenet_groups.id') + ->select(['collections.*', DB::raw('UNIX_TIMESTAMP(collections.date) AS udate'), 'usenet_groups.name as groupname']) + ->get(); if (empty($collections)) { return false; @@ -192,7 +166,7 @@ class NZB $XMLWriter->endElement(); //head foreach ($collections as $collection) { - $binaries = DB::select(sprintf($this->_binariesQuery, $collection->id)); + $binaries = Binary::whereCollectionsId($collection->id)->select(['id', 'name', 'totalparts'])->orderBy('name')->get(); if (empty($binaries)) { return false; } @@ -200,7 +174,7 @@ class NZB $poster = $collection->fromname; foreach ($binaries as $binary) { - $parts = DB::select(sprintf($this->_partsQuery, $binary->id)); + $parts = Part::whereBinariesId($binary->id)->distinct()->select(['messageid', 'size', 'partnumber'])->orderBy('partnumber')->get(); if (empty($parts)) { return false; } diff --git a/Blacklight/processing/ProcessReleases.php b/Blacklight/processing/ProcessReleases.php index 190c4e221..c9fa88a65 100755 --- a/Blacklight/processing/ProcessReleases.php +++ b/Blacklight/processing/ProcessReleases.php @@ -658,8 +658,6 @@ class ProcessReleases if ($releases->count() > 0) { $total = $releases->count(); - // Init vars for writing the NZB's. - $this->nzb->initiateForWrite(); foreach ($releases as $release) { if ($this->nzb->writeNzbForReleaseId($release)) { $nzbCount++; diff --git a/Changelog b/Changelog index 64a77b5ef..42483297a 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2019-03-19 DariusIII + * Chg: Use query builder to fetch collections/binaries and parts when creating nzbs, drop initiateforwrite and setQueries functions * Chg: Update tinyMCE to version 5.0.3 * Chg: Update pragmarx/firewall (v2.2.1 => v2.2.2) 2019-03-18 DariusIII