Unify caching to reduce the number of Nexus calls on the build server

This commit is contained in:
Timothy Baldridge 2019-11-07 18:36:01 -07:00
parent 42d8347c76
commit 2fb857a093
4 changed files with 9 additions and 40 deletions

View File

@ -82,7 +82,5 @@ namespace Wabbajack.Common
}
public static string WabbajackCacheLocation = "http://build.wabbajack.org/nexus_api_cache/";
public static TimeSpan NexusCacheExpiry = new TimeSpan(1, 0, 0, 0);
}
}

View File

@ -18,7 +18,9 @@ namespace Wabbajack.Lib.Downloaders
if (general.modID != null && general.fileID != null && general.gameName != null)
{
var info = new NexusApiClient().GetModInfo(general.gameName, general.modID);
var name = (string)general.gameName;
var game = GameRegistry.GetByMO2ArchiveName(name).Game;
var info = new NexusApiClient().GetModInfo(game, general.modID);
return new State
{
GameName = general.gameName,
@ -30,7 +32,7 @@ namespace Wabbajack.Lib.Downloaders
UploaderProfile = info.uploaded_users_profile_url,
ModName = info.name,
SlideShowPic = info.picture_url,
NexusURL = NexusApiUtils.GetModURL(info.game_name, info.mod_id),
NexusURL = NexusApiUtils.GetModURL(game, info.mod_id),
Summary = info.summary,
Adult = info.contains_adult_content

View File

@ -272,41 +272,10 @@ namespace Wabbajack.Lib.NexusApi
return GetCached<GetModFilesResponse>(url).files;
}
public ModInfo GetModInfo(string gameName, string modId)
public ModInfo GetModInfo(Game game, string modId)
{
if (!Directory.Exists(Consts.NexusCacheDirectory))
Directory.CreateDirectory(Consts.NexusCacheDirectory);
ModInfo result = null;
TOP:
var path = Path.Combine(Consts.NexusCacheDirectory, $"mod-info-{gameName}-{modId}.json");
try
{
if (File.Exists(path))
{
result = path.FromJSON<ModInfo>();
if (result._internal_version != CACHED_VERSION_NUMBER)
{
File.Delete(path);
goto TOP;
}
return result;
}
}
catch (Exception)
{
File.Delete(path);
}
var url = $"https://api.nexusmods.com/v1/games/{ConvertGameName(gameName)}/mods/{modId}.json";
result = Get<ModInfo>(url);
result.game_name = gameName;
result.mod_id = modId;
result._internal_version = CACHED_VERSION_NUMBER;
result.ToJSON(path);
return result;
var url = $"https://api.nexusmods.com/v1/games/{GameRegistry.Games[game].NexusName}/mods/{modId}.json";
return GetCached<ModInfo>(url);
}
public EndorsementResponse EndorseMod(NexusDownloader.State mod)

View File

@ -9,9 +9,9 @@ namespace Wabbajack.Lib.NexusApi
return GameRegistry.GetByMO2ArchiveName(gameName)?.NexusName ?? gameName.ToLower();
}
public static string GetModURL(string argGameName, string argModId)
public static string GetModURL(Game game, string argModId)
{
return $"https://nexusmods.com/{ConvertGameName(argGameName)}/mods/{argModId}";
return $"https://nexusmods.com/{GameRegistry.Games[game].NexusName}/mods/{argModId}";
}
public static string FixupSummary(string argSummary)