diff --git a/newznab/controllers/Books.php b/newznab/controllers/Books.php index 51999a51e..7fdd1b411 100644 --- a/newznab/controllers/Books.php +++ b/newznab/controllers/Books.php @@ -63,7 +63,7 @@ class Books /** * @param array $options Class instances / Echo to cli. */ - public function __construct(array $options = array()) + public function __construct(array $options =[]) { $defaults = [ 'Echo' => false, @@ -84,6 +84,8 @@ class Books if ($this->pdo->getSetting('lookupbooks') == 2) { $this->renamed = 'AND isrenamed = 1'; } + + $this->failCache = []; } public function getBookInfo($id) @@ -142,7 +144,7 @@ class Books return $res['num']; } - public function getBookCount($cat, $maxage = -1, $excludedcats = array()) + public function getBookCount($cat, $maxage = -1, $excludedcats =[]) { $browseby = $this->getBrowseBy(); @@ -175,7 +177,7 @@ class Books return $res['num']; } - public function getBookRange($cat, $start, $num, $orderby, $excludedcats = array()) + public function getBookRange($cat, $start, $num, $orderby, $excludedcats =[]) { $browseby = $this->getBrowseBy(); @@ -344,7 +346,7 @@ class Books */ public function processBookReleases() { - $bookids = array(); + $bookids =[]; if (preg_match('/^\d+$/', $this->bookreqids)) { $bookids[] = $this->bookreqids; } else { @@ -404,11 +406,18 @@ class Books // Do a local lookup first $bookCheck = $this->getBookInfoByName('', $bookInfo); - if ($bookCheck === false) { + if ($bookCheck === false && in_array($bookInfo, $this->failCache)) { + // Lookup recently failed, no point trying again + if ($this->echooutput) { + $this->pdo->log->doEcho($this->pdo->log->headerOver('Cached previous failure. Skipping.') . PHP_EOL); + } + $bookId = -2; + } else if ($bookCheck === false) { $bookId = $this->updateBookInfo($bookInfo); $usedAmazon = true; if ($bookId === false) { $bookId = -2; + $this->failCache[] = $bookInfo; } } else { $bookId = $bookCheck['id']; @@ -484,7 +493,7 @@ class Books { $ri = new \ReleaseImage($this->pdo); - $book = array(); + $book =[]; $amaz = false; if ($bookInfo != '') { diff --git a/newznab/controllers/Konsole.php b/newznab/controllers/Konsole.php index e9662055a..70d47ede6 100644 --- a/newznab/controllers/Konsole.php +++ b/newznab/controllers/Konsole.php @@ -59,7 +59,7 @@ class Konsole /** * @param array $options Class instances / Echo to cli. */ - public function __construct(array $options = array()) + public function __construct(array $options =[]) { $defaults = [ 'Echo' => false, @@ -81,6 +81,8 @@ class Konsole $this->renamed = 'AND isrenamed = 1'; } //$this->cleanconsole = ($this->pdo->getSetting('lookupgames') == 2) ? 'AND isrenamed = 1' : ''; + + $this->failCache =[]; } public function getConsoleInfo($id) @@ -136,7 +138,7 @@ class Konsole return ($res === false ? 0 : $res['num']); } - public function getConsoleCount($cat, $maxage = -1, $excludedcats = array()) + public function getConsoleCount($cat, $maxage = -1, $excludedcats =[]) { $catsrch = ''; if (count($cat) > 0 && $cat[0] != -1) { @@ -160,7 +162,7 @@ class Konsole return ($res === false ? 0 : $res["num"]); } - public function getConsoleRange($cat, $start, $num, $orderby, $excludedcats = array()) + public function getConsoleRange($cat, $start, $num, $orderby, $excludedcats =[]) { $browseby = $this->getBrowseBy(); @@ -272,7 +274,7 @@ class Konsole public function makeFieldLinks($data, $field) { $tmpArr = explode(', ', $data[$field]); - $newArr = array(); + $newArr =[]; $i = 0; foreach ($tmpArr as $ta) { if (trim($ta) == '') { @@ -365,7 +367,7 @@ class Konsole return $consoleId; } - protected function _matchConToGameInfo($gameInfo = array(), $con = array()) + protected function _matchConToGameInfo($gameInfo =[], $con =[]) { $matched = false; @@ -414,7 +416,7 @@ class Konsole protected function _setConBeforeMatch($amaz, $gameInfo) { - $con = array(); + $con =[]; $con['platform'] = (string)$amaz->Items->Item->ItemAttributes->Platform; if (empty($con['platform'])) { $con['platform'] = $gameInfo['platform']; @@ -437,7 +439,7 @@ class Konsole protected function _setConAfterMatch($amaz) { - $con = array(); + $con =[]; $con['asin'] = (string)$amaz->Items->Item->ASIN; $con['url'] = (string)$amaz->Items->Item->DetailPageURL; @@ -538,7 +540,7 @@ class Konsole $gen = new \Genres(['Settings' => $this->pdo]); $defaultGenres = $gen->getGenres(\Genres::CONSOLE_TYPE); - $genreassoc = array(); + $genreassoc =[]; foreach ($defaultGenres as $dg) { $genreassoc[$dg['id']] = strtolower($dg['title']); } @@ -612,7 +614,7 @@ class Konsole return $platform; } - protected function _updateConsoleTable($con = array()) + protected function _updateConsoleTable($con =[]) { $ri = new \ReleaseImage($this->pdo); @@ -746,9 +748,19 @@ class Konsole // Check for existing console entry. $gameCheck = $this->getConsoleInfoByName($gameInfo['title'], $gameInfo['platform']); - if ($gameCheck === false) { + if ($gameCheck === false && in_array($gameInfo['title'] . $gameInfo['platform'], $this->failCache)) { + // Lookup recently failed, no point trying again + if ($this->echooutput) { + $this->pdo->log->doEcho($this->pdo->log->headerOver('Cached previous failure. Skipping.') . PHP_EOL); + } + $gameId = -2; + } else if ($gameCheck === false) { $gameId = $this->updateConsoleInfo($gameInfo); $usedAmazon = true; + if ($gameId === false) { + $gameId = -2; + $this->failCache[] = $gameInfo['title'] . $gameInfo['platform']; + } } else { if ($this->echooutput) { $this->pdo->log->doEcho( @@ -790,7 +802,7 @@ class Konsole function parseTitle($releasename) { $releasename = preg_replace('/\sMulti\d?\s/i', '', $releasename); - $result = array(); + $result =[]; // Get name of the game from name of release. if (preg_match('/^(.+((abgx360EFNet|EFNet\sFULL|FULL\sabgxEFNet|abgx\sFULL|abgxbox360EFNet)\s|illuminatenboard\sorg|Place2(hom|us)e.net|united-forums? co uk|\(\d+\)))?(?P