From 852cb563ba0d6c68473d8b1854aa9617bb957c11 Mon Sep 17 00:00:00 2001 From: Sude Date: Sun, 6 Mar 2016 14:02:30 +0200 Subject: [PATCH] Reduce the amount HTTP requests Save game details json for later use when DLC info is downloaded in Downloader::getGames. This reduces the amount of HTTP requests because we don't need to download the info again in Downloader::getGameDetails. --- include/downloader.h | 1 + src/downloader.cpp | 27 ++++++++------------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/include/downloader.h b/include/downloader.h index 666eecd..6d69125 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -52,6 +52,7 @@ class gameItem { std::string name; std::string id; std::vector dlcnames; + Json::Value gamedetailsjson; }; class Downloader diff --git a/src/downloader.cpp b/src/downloader.cpp index f372253..71f46b1 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -315,9 +315,13 @@ int Downloader::getGameDetails() game.filterWithPriorities(conf); Json::Value gameDetailsJSON; + if (!gameItems[i].gamedetailsjson.empty()) + gameDetailsJSON = gameItems[i].gamedetailsjson; + if (game.extras.empty() && config.bExtras) // Try to get extras from account page if API didn't return any extras { - gameDetailsJSON = this->getGameDetailsJSON(gameItems[i].id); + if (gameDetailsJSON.empty()) + gameDetailsJSON = this->getGameDetailsJSON(gameItems[i].id); game.extras = this->getExtrasFromJSON(gameDetailsJSON, gameItems[i].name); } if (config.bSaveSerials) @@ -2262,24 +2266,9 @@ std::vector Downloader::getGames() if (bDownloadDLCInfo) { - std::string gameinfo = this->getResponse("https://www.gog.com/account/gameDetails/" + game.id + ".json"); - Json::Value info; - if (!jsonparser->parse(gameinfo, info)) - { - #ifdef DEBUG - std::cerr << "DEBUG INFO (Downloader::getGames)" << std::endl << gameinfo << std::endl; - #endif - std::cout << jsonparser->getFormattedErrorMessages(); - delete jsonparser; - exit(1); - } - else - { - #ifdef DEBUG - std::cerr << "DEBUG INFO (Downloader::getGames)" << std::endl << info << std::endl; - #endif - game.dlcnames = Util::getDLCNamesFromJSON(info["dlcs"]); - } + game.gamedetailsjson = this->getGameDetailsJSON(game.id); + if (!game.gamedetailsjson.empty()) + game.dlcnames = Util::getDLCNamesFromJSON(game.gamedetailsjson["dlcs"]); } } games.push_back(game);