diff --git a/CFLookup/Jobs/CacheMCOverTime.cs b/CFLookup/Jobs/CacheMCOverTime.cs index 0a89c21..e11f35a 100644 --- a/CFLookup/Jobs/CacheMCOverTime.cs +++ b/CFLookup/Jobs/CacheMCOverTime.cs @@ -16,7 +16,7 @@ public static async Task RunAsync(PerformContext context) var _rdb = _redis.GetDatabase(5); - var stats = await SharedMethods.GetMinecraftStatsOverTime(_db, CancellationToken.None, 24 * 60); + var stats = await SharedMethods.GetMinecraftStatsOverTime(_db, CancellationToken.None); var renderers = new List(); var ModLoaderStats = new Dictionary>(); @@ -110,7 +110,7 @@ public static async Task RunAsync(PerformContext context) new XAxis { Type = "datetime", - MinRange = 3600000 + MinRange = 24 * 3600000 } }, Legend = new Legend diff --git a/CFLookup/SharedMethods.cs b/CFLookup/SharedMethods.cs index 8496ae9..64625ea 100644 --- a/CFLookup/SharedMethods.cs +++ b/CFLookup/SharedMethods.cs @@ -355,17 +355,18 @@ public static async Task> GetMinecraftModpack return mcVersionModCount; } - public static async Task>>> GetMinecraftStatsOverTime(MSSQLDB _db, CancellationToken cancellationToken, int? datapoints = 1000) + public static async Task>>> GetMinecraftStatsOverTime(MSSQLDB _db, CancellationToken cancellationToken) { var stats = await _db.ExecuteReader( $@" -SELECT timestamp_utc, stats, RowNumber -FROM ( - SELECT ROW_NUMBER() OVER (ORDER BY statId DESC) AS RowNumber, * - FROM MinecraftModStatsOverTime -) AS MCStats -{(datapoints.HasValue && datapoints > 0 ? $"WHERE RowNumber <= {datapoints}" : "")} -ORDER BY RowNumber DESC +WITH DailyLatest AS ( + SELECT *, + ROW_NUMBER() OVER (PARTITION BY CAST(timestamp_utc AS DATE) ORDER BY timestamp_utc DESC) AS RowNumber + FROM MinecraftModStatsOverTime WITH(NOLOCK) +) +SELECT * +FROM DailyLatest +WHERE RowNumber = 1 "); var Stats = new Dictionary>>(); while (stats.Read())