mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
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:
parent
173481a6f6
commit
852cb563ba
@ -52,6 +52,7 @@ class gameItem {
|
||||
std::string name;
|
||||
std::string id;
|
||||
std::vector<std::string> dlcnames;
|
||||
Json::Value gamedetailsjson;
|
||||
};
|
||||
|
||||
class Downloader
|
||||
|
@ -315,8 +315,12 @@ 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
|
||||
{
|
||||
if (gameDetailsJSON.empty())
|
||||
gameDetailsJSON = this->getGameDetailsJSON(gameItems[i].id);
|
||||
game.extras = this->getExtrasFromJSON(gameDetailsJSON, gameItems[i].name);
|
||||
}
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user