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.
This commit is contained in:
Sude 2016-03-06 14:02:30 +02:00
parent 173481a6f6
commit 852cb563ba
2 changed files with 9 additions and 19 deletions

View File

@ -52,6 +52,7 @@ class gameItem {
std::string name; std::string name;
std::string id; std::string id;
std::vector<std::string> dlcnames; std::vector<std::string> dlcnames;
Json::Value gamedetailsjson;
}; };
class Downloader class Downloader

View File

@ -315,9 +315,13 @@ int Downloader::getGameDetails()
game.filterWithPriorities(conf); game.filterWithPriorities(conf);
Json::Value gameDetailsJSON; 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 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); game.extras = this->getExtrasFromJSON(gameDetailsJSON, gameItems[i].name);
} }
if (config.bSaveSerials) if (config.bSaveSerials)
@ -2262,24 +2266,9 @@ std::vector<gameItem> Downloader::getGames()
if (bDownloadDLCInfo) if (bDownloadDLCInfo)
{ {
std::string gameinfo = this->getResponse("https://www.gog.com/account/gameDetails/" + game.id + ".json"); game.gamedetailsjson = this->getGameDetailsJSON(game.id);
Json::Value info; if (!game.gamedetailsjson.empty())
if (!jsonparser->parse(gameinfo, info)) game.dlcnames = Util::getDLCNamesFromJSON(game.gamedetailsjson["dlcs"]);
{
#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"]);
}
} }
} }
games.push_back(game); games.push_back(game);