From f04947bf08f2a1b268bbdf4c6d831f4eff0100eb Mon Sep 17 00:00:00 2001 From: Darko Date: Thu, 13 Aug 2015 13:15:31 +0200 Subject: [PATCH] Fix the query properly by kevin123. --- newznab/controllers/Sharing.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/newznab/controllers/Sharing.php b/newznab/controllers/Sharing.php index ace6ff3c7..374f1ebf8 100644 --- a/newznab/controllers/Sharing.php +++ b/newznab/controllers/Sharing.php @@ -323,20 +323,20 @@ Class Sharing } // Update first time seen. - $siteTimes = $this->pdo->queryDirect( - 'SELECT createddate, siteid FROM release_comments WHERE createddate > \'2005-01-01\' GROUP BY siteid ORDER BY createddate ASC' - ); - if ($siteTimes instanceof \Traversable && $siteTimes->rowCount()) { - foreach ($siteTimes as $site) { - $this->pdo->queryExec( - sprintf( - 'UPDATE sharing_sites SET first_time = %s WHERE site_guid = %s', - $this->pdo->escapeString($site['createddate']), - $this->pdo->escapeString($site['siteid']) - ) - ); - } - } + $this->pdo->queryExec( + sprintf(" + UPDATE sharing_sites ss + INNER JOIN + (SELECT siteid, createddate + FROM release_comments + WHERE createddate > '2005-01-01' + GROUP BY siteid + ORDER BY createddate ASC) rc + ON ss.site_guid = rc.siteid + SET ss.first_time = rc.createddate + WHERE ss.first_time IS NULL OR ss.first_time > rc.createddate" + ) + ); } /**