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 id;
std::vector<std::string> dlcnames;
Json::Value gamedetailsjson;
};
class Downloader

View File

@ -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<gameItem> 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);