Fix how we handle UTC dates with SQL

This commit is contained in:
Timothy Baldridge 2020-05-12 17:19:54 -06:00
parent 40640dff5a
commit b99805fd58
2 changed files with 21 additions and 2 deletions

View File

@ -54,7 +54,7 @@ namespace Wabbajack.BuildServer.Controllers
{
var api = await NexusApiClient.Get(Request.Headers["apikey"].FirstOrDefault());
result = await api.GetModInfo(game, ModId, false);
await _sql.AddNexusModInfo(game, ModId, DateTime.UtcNow, result);
await _sql.AddNexusModInfo(game, ModId, result.updated_time, result);
method = "NOT_CACHED";
@ -82,7 +82,9 @@ namespace Wabbajack.BuildServer.Controllers
{
var api = await NexusApiClient.Get(Request.Headers["apikey"].FirstOrDefault());
result = await api.GetModFiles(game, ModId, false);
await _sql.AddNexusModFiles(game, ModId, DateTime.UtcNow, result);
var date = result.files.Select(f => f.uploaded_time).OrderByDescending(o => o).FirstOrDefault();
date = date == default ? DateTime.UtcNow : date;
await _sql.AddNexusModFiles(game, ModId, date, result);
method = "NOT_CACHED";
Interlocked.Increment(ref ForwardCount);

View File

@ -17,6 +17,23 @@ namespace Wabbajack.Server.DataLayer
SqlMapper.AddTypeHandler(new JsonMapper<CDNFileDefinition>());
SqlMapper.AddTypeHandler(new VersionMapper());
SqlMapper.AddTypeHandler(new GameMapper());
SqlMapper.AddTypeHandler(new DateTimeHandler());
}
/// <summary>
/// Needed to make sure dates are all in UTC format
/// </summary>
private class DateTimeHandler : SqlMapper.TypeHandler<DateTime>
{
public override void SetValue(IDbDataParameter parameter, DateTime value)
{
parameter.Value = value;
}
public override DateTime Parse(object value)
{
return DateTime.SpecifyKind((DateTime)value, DateTimeKind.Utc);
}
}
class JsonMapper<T> : SqlMapper.TypeHandler<T>