From 3d0269b2a5d8659bb1fbe0703c0bb934b161d43f Mon Sep 17 00:00:00 2001 From: NoLifeKing Date: Mon, 18 Dec 2023 07:31:25 +0100 Subject: [PATCH 01/16] fix: Cache games, mods and files in the job, to make the experience better in the frontend --- CFLookup/Jobs/GetLatestUpdatedModPerGame.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs index cb860d1..2cd2be9 100644 --- a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs +++ b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs @@ -47,6 +47,7 @@ public static async Task RunAsync(PerformContext context) foreach(var game in allGames) { Console.WriteLine($"Starting to check for latest updated mod for {game.Name}"); + await _db.StringSetAsync($"cf-game-{game.Id}", JsonSerializer.Serialize(game), TimeSpan.FromDays(1)); var latestUpdatedMod = await cfClient.SearchModsAsync(game.Id, sortField: ModsSearchSortField.LastUpdated, sortOrder: ModsSearchSortOrder.Descending, pageSize: 1); if(latestUpdatedMod != null && latestUpdatedMod.Pagination.ResultCount > 0) @@ -61,6 +62,9 @@ public static async Task RunAsync(PerformContext context) latestUpdatedFileData = latestUpdatedFile; } + await _redis.StringSetAsync($"cf-mod-{mod.Id}", JsonSerializer.Serialize(mod), TimeSpan.FromDays(1)); + await _redis.StringSetAsync($"cf-file-{latestUpdatedFile.Id}", JsonSerializer.Serialize(file), TimeSpan.FromDays(1)); + var existingGame = await db.ExecuteSingleRowAsync( "SELECT * FROM fileProcessingStatus WHERE gameId = @gameId", new SqlParameter("@gameId", game.Id) From 77515fed94bf10394bca263921fbbaeb6adb5b5f Mon Sep 17 00:00:00 2001 From: NoLifeKing Date: Mon, 18 Dec 2023 07:33:34 +0100 Subject: [PATCH 02/16] fix: Fixing the fix I made --- CFLookup/Jobs/GetLatestUpdatedModPerGame.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs index 2cd2be9..6f3d4d5 100644 --- a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs +++ b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs @@ -4,7 +4,7 @@ using CurseForge.APIClient.Models.Mods; using Hangfire.Server; using Microsoft.Data.SqlClient; -using Newtonsoft.Json; +using System.Text.Json; using StackExchange.Redis; using System.Text; @@ -132,7 +132,7 @@ await db.ExecuteNonQueryAsync( flags = 4 }; - var json = JsonConvert.SerializeObject(payload); + var json = JsonSerializer.Serialize(payload); var content = new StringContent(json, Encoding.UTF8, "application/json"); await httpClient.PostAsync(discordWebhook, content); } From 4615adcabc366851e708c42ffefd189ca71e5fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 18 Dec 2023 07:37:11 +0100 Subject: [PATCH 03/16] fix: Fix the previous fixes --- CFLookup/Jobs/GetLatestUpdatedModPerGame.cs | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs index 6f3d4d5..65ef355 100644 --- a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs +++ b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs @@ -4,9 +4,9 @@ using CurseForge.APIClient.Models.Mods; using Hangfire.Server; using Microsoft.Data.SqlClient; -using System.Text.Json; using StackExchange.Redis; using System.Text; +using System.Text.Json; namespace CFLookup.Jobs { @@ -14,8 +14,8 @@ public class GetLatestUpdatedModPerGame { public static async Task RunAsync(PerformContext context) { - using(var scope = Program.ServiceProvider.CreateScope()) - { + using (var scope = Program.ServiceProvider.CreateScope()) + { var cfClient = scope.ServiceProvider.GetRequiredService(); var db = scope.ServiceProvider.GetRequiredService(); var _redis = scope.ServiceProvider.GetRequiredService(); @@ -26,11 +26,11 @@ public static async Task RunAsync(PerformContext context) var allGames = new List(); var games = await cfClient.GetGamesAsync(); - if(games != null && games.Pagination.ResultCount > 0) + if (games != null && games.Pagination.ResultCount > 0) { allGames.AddRange(games.Data); var index = 0; - while(games.Pagination.ResultCount > 0) + while (games.Pagination.ResultCount > 0) { index += games.Pagination.PageSize; games = await cfClient.GetGamesAsync(index); @@ -44,13 +44,13 @@ public static async Task RunAsync(PerformContext context) Mod? latestUpdatedModData = null; CurseForge.APIClient.Models.Files.File? latestUpdatedFileData = null; - foreach(var game in allGames) + foreach (var game in allGames) { Console.WriteLine($"Starting to check for latest updated mod for {game.Name}"); await _db.StringSetAsync($"cf-game-{game.Id}", JsonSerializer.Serialize(game), TimeSpan.FromDays(1)); var latestUpdatedMod = await cfClient.SearchModsAsync(game.Id, sortField: ModsSearchSortField.LastUpdated, sortOrder: ModsSearchSortOrder.Descending, pageSize: 1); - if(latestUpdatedMod != null && latestUpdatedMod.Pagination.ResultCount > 0) + if (latestUpdatedMod != null && latestUpdatedMod.Pagination.ResultCount > 0) { var mod = latestUpdatedMod.Data.First(); var latestUpdatedFile = mod.LatestFiles.OrderByDescending(f => f.FileDate).First(); @@ -62,15 +62,15 @@ public static async Task RunAsync(PerformContext context) latestUpdatedFileData = latestUpdatedFile; } - await _redis.StringSetAsync($"cf-mod-{mod.Id}", JsonSerializer.Serialize(mod), TimeSpan.FromDays(1)); - await _redis.StringSetAsync($"cf-file-{latestUpdatedFile.Id}", JsonSerializer.Serialize(file), TimeSpan.FromDays(1)); + await _db.StringSetAsync($"cf-mod-{mod.Id}", JsonSerializer.Serialize(mod), TimeSpan.FromDays(1)); + await _db.StringSetAsync($"cf-file-{latestUpdatedFile.Id}", JsonSerializer.Serialize(latestUpdatedFile), TimeSpan.FromDays(1)); var existingGame = await db.ExecuteSingleRowAsync( "SELECT * FROM fileProcessingStatus WHERE gameId = @gameId", new SqlParameter("@gameId", game.Id) ); - if(existingGame == null) + if (existingGame == null) { // New game, insert it await db.ExecuteNonQueryAsync( @@ -102,13 +102,13 @@ await db.ExecuteNonQueryAsync( Console.WriteLine($"Last updated mod was updated {lastUpdatedMod}"); - if(lastUpdatedMod < DateTimeOffset.UtcNow.AddHours(-3) && latestUpdatedModData != null && latestUpdatedFileData != null) + if (lastUpdatedMod < DateTimeOffset.UtcNow.AddHours(-3) && latestUpdatedModData != null && latestUpdatedFileData != null) { Console.WriteLine("No mods were updated in the last 3 hours, file processing might be down."); var warned = await _db.StringGetAsync("cf-file-processing-warning"); - if(warned.HasValue && warned == "true") + if (warned.HasValue && warned == "true") { Console.WriteLine("Already warned about this, skipping."); return; @@ -120,7 +120,7 @@ await db.ExecuteNonQueryAsync( Environment.GetEnvironmentVariable("DISCORD_WEBHOOK", EnvironmentVariableTarget.Process) ?? string.Empty; - if(!string.IsNullOrWhiteSpace(discordWebhook)) + if (!string.IsNullOrWhiteSpace(discordWebhook)) { var message = @$"No mods were updated in the last 3 hours, file processing might be down. Last updated mod was updated {lastUpdatedMod}, and it was {latestUpdatedModData.Name} From 9d2c9653ecb804050f2935e69a76088955840c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 18 Dec 2023 07:54:51 +0100 Subject: [PATCH 04/16] fix: So that's why the rows weren't striped --- CFLookup/Pages/FileProcessingInfo.cshtml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CFLookup/Pages/FileProcessingInfo.cshtml b/CFLookup/Pages/FileProcessingInfo.cshtml index 7d2cc03..75d9b7b 100644 --- a/CFLookup/Pages/FileProcessingInfo.cshtml +++ b/CFLookup/Pages/FileProcessingInfo.cshtml @@ -14,15 +14,15 @@ Latest update + @foreach (var row in Model.ModFiles) { - - - @row.Game.Name - @row.Mod.Name - @row.File.FileName - @row.LatestUpdatedUtc - - + + @row.Game.Name + @row.Mod.Name + @row.File.FileName + @row.LatestUpdatedUtc + } + \ No newline at end of file From fec423ec7f6351b3f947e7bcaf5fe41da52ae12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 18 Dec 2023 07:58:47 +0100 Subject: [PATCH 05/16] feat: Easier to read how long ago it was updated --- CFLookup/Pages/FileProcessingInfo.cshtml | 2 +- CFLookup/Pages/FileProcessingInfo.cshtml.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CFLookup/Pages/FileProcessingInfo.cshtml b/CFLookup/Pages/FileProcessingInfo.cshtml index 75d9b7b..296433d 100644 --- a/CFLookup/Pages/FileProcessingInfo.cshtml +++ b/CFLookup/Pages/FileProcessingInfo.cshtml @@ -21,7 +21,7 @@ @row.Game.Name @row.Mod.Name @row.File.FileName - @row.LatestUpdatedUtc + @row.SinceLatestUpdate.ToHumanReadableFormat() } diff --git a/CFLookup/Pages/FileProcessingInfo.cshtml.cs b/CFLookup/Pages/FileProcessingInfo.cshtml.cs index 8d56df0..8ed1d77 100644 --- a/CFLookup/Pages/FileProcessingInfo.cshtml.cs +++ b/CFLookup/Pages/FileProcessingInfo.cshtml.cs @@ -1,6 +1,5 @@ using CFLookup.Models; using CurseForge.APIClient; -using CurseForge.APIClient.Models.Files; using CurseForge.APIClient.Models.Games; using CurseForge.APIClient.Models.Mods; using Microsoft.AspNetCore.Mvc; @@ -29,11 +28,11 @@ public async Task OnGetAsync() { var gameProcessingInfo = await _db.ExecuteListAsync("SELECT * FROM fileProcessingStatus ORDER BY last_updated_utc DESC"); - foreach(var info in gameProcessingInfo) + foreach (var info in gameProcessingInfo) { Game game; var gameCache = await _redis.StringGetAsync($"cf-game-{info.GameId}"); - if(!gameCache.IsNullOrEmpty) + if (!gameCache.IsNullOrEmpty) { game = JsonSerializer.Deserialize(gameCache)!; } @@ -45,7 +44,7 @@ public async Task OnGetAsync() Mod mod; var modCache = await _redis.StringGetAsync($"cf-mod-{info.ModId}"); - if(!modCache.IsNullOrEmpty) + if (!modCache.IsNullOrEmpty) { mod = JsonSerializer.Deserialize(modCache)!; } @@ -57,7 +56,7 @@ public async Task OnGetAsync() CurseForge.APIClient.Models.Files.File file; var fileCache = await _redis.StringGetAsync($"cf-file-{info.FileId}"); - if(!fileCache.IsNullOrEmpty) + if (!fileCache.IsNullOrEmpty) { file = JsonSerializer.Deserialize(fileCache)!; } @@ -88,5 +87,6 @@ public class GameModFileProcessingInfo public Mod Mod { get; set; } public CurseForge.APIClient.Models.Files.File File { get; set; } public DateTimeOffset LatestUpdatedUtc { get; set; } + public TimeSpan SinceLatestUpdate => DateTimeOffset.UtcNow - LatestUpdatedUtc; } } From 859ad45a84ff6b4bc4da7142e608179d517fbb04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 18 Dec 2023 08:00:24 +0100 Subject: [PATCH 06/16] chore: Format the code better --- CFLookup/Pages/FileProcessingInfo.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CFLookup/Pages/FileProcessingInfo.cshtml b/CFLookup/Pages/FileProcessingInfo.cshtml index 296433d..80d4a8e 100644 --- a/CFLookup/Pages/FileProcessingInfo.cshtml +++ b/CFLookup/Pages/FileProcessingInfo.cshtml @@ -21,7 +21,7 @@ @row.Game.Name @row.Mod.Name @row.File.FileName - @row.SinceLatestUpdate.ToHumanReadableFormat() + @row.SinceLatestUpdate.ToHumanReadableFormat() } From fd5f11bf5d66926370c71ee6269fa2869d60bf6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 18 Dec 2023 08:01:30 +0100 Subject: [PATCH 07/16] fix: Humanreadable format with day support --- CFLookup/SharedMethods.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CFLookup/SharedMethods.cs b/CFLookup/SharedMethods.cs index 8313e0b..6e1fd28 100644 --- a/CFLookup/SharedMethods.cs +++ b/CFLookup/SharedMethods.cs @@ -71,7 +71,7 @@ public static async Task> GetCategoryInfo(IDatabaseAsync _redis, FileIds = new List { fileId } }); - if(file.Data.Count == 0) + if (file.Data.Count == 0) return (null, null, null); var mod = await _cfApiClient.GetModAsync(file.Data[0].ModId); @@ -359,7 +359,8 @@ public static string GetProjectNameFromFile(string url) public static string ToHumanReadableFormat(this TimeSpan timeSpan) { - return timeSpan.TotalSeconds <= 0 ? "0 seconds" : string.Format("{0}{1}{2}", + return timeSpan.TotalSeconds <= 0 ? "0 seconds" : string.Format("{0}{1}{2}{3}", + timeSpan.Days > 0 ? string.Format($"{timeSpan.Days:n0} day{{0}}, ", timeSpan.Days != 1 ? "s" : string.Empty) : string.Empty, timeSpan.Hours > 0 ? string.Format($"{timeSpan.Hours:n0} hour{{0}}, ", timeSpan.Hours != 1 ? "s" : string.Empty) : string.Empty, timeSpan.Minutes > 0 ? string.Format($"{timeSpan.Minutes:n0} minute{{0}}, ", timeSpan.Minutes != 1 ? "s" : string.Empty) : string.Empty, timeSpan.Seconds > 0 ? string.Format($"{timeSpan.Seconds:n0} second{{0}}", timeSpan.Seconds != 1 ? "s" : string.Empty) : string.Empty From 058b6b8c26c8fccf732229f4850095b91e7648b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 18 Dec 2023 08:01:43 +0100 Subject: [PATCH 08/16] chore: Added "ago" --- CFLookup/Pages/FileProcessingInfo.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CFLookup/Pages/FileProcessingInfo.cshtml b/CFLookup/Pages/FileProcessingInfo.cshtml index 80d4a8e..60bb305 100644 --- a/CFLookup/Pages/FileProcessingInfo.cshtml +++ b/CFLookup/Pages/FileProcessingInfo.cshtml @@ -21,7 +21,7 @@ @row.Game.Name @row.Mod.Name @row.File.FileName - @row.SinceLatestUpdate.ToHumanReadableFormat() + @row.SinceLatestUpdate.ToHumanReadableFormat() ago } From c90143bfa643bb95077d365145f96a9a4c61199b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 18 Dec 2023 08:05:54 +0100 Subject: [PATCH 09/16] ci: Fix concurrency --- .github/workflows/CI.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 69b74a8..ae93410 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -4,6 +4,10 @@ on: push: branches: [master] +concurrency: + group: environment-${{ github.ref }}-ci + cancel-in-progress: true + jobs: generate: runs-on: ubuntu-latest From 60fd02abdd6370020d34d9efb8908d62561a2015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 18 Dec 2023 13:09:32 +0100 Subject: [PATCH 10/16] feat: Easier to read time format --- CFLookup/Pages/FileProcessingInfo.cshtml | 2 +- CFLookup/SharedMethods.cs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CFLookup/Pages/FileProcessingInfo.cshtml b/CFLookup/Pages/FileProcessingInfo.cshtml index 60bb305..2151924 100644 --- a/CFLookup/Pages/FileProcessingInfo.cshtml +++ b/CFLookup/Pages/FileProcessingInfo.cshtml @@ -21,7 +21,7 @@ @row.Game.Name @row.Mod.Name @row.File.FileName - @row.SinceLatestUpdate.ToHumanReadableFormat() ago + @row.SinceLatestUpdate.ToHumanReadableFormat(true) ago } diff --git a/CFLookup/SharedMethods.cs b/CFLookup/SharedMethods.cs index 6e1fd28..e18b72d 100644 --- a/CFLookup/SharedMethods.cs +++ b/CFLookup/SharedMethods.cs @@ -357,13 +357,22 @@ public static string GetProjectNameFromFile(string url) return Path.GetFileName(url); } - public static string ToHumanReadableFormat(this TimeSpan timeSpan) + public static string ToHumanReadableFormat(this TimeSpan timeSpan, bool shortText = false, double skipMinutesAndSecondsAfterHours = 2.0f) { + var secondText = shortText ? "s" : " second" + (timeSpan.Seconds != 1 ? "s" : string.Empty); + var minuteText = shortText ? "m" : " minute" + (timeSpan.Minutes != 1 ? "s" : string.Empty); + var hourText = shortText ? "h" : " hour" + (timeSpan.Hours != 1 ? "s" : string.Empty); + var dayText = shortText ? "d" : " day" + (timeSpan.Days != 1 ? "s" : string.Empty); + return timeSpan.TotalSeconds <= 0 ? "0 seconds" : string.Format("{0}{1}{2}{3}", - timeSpan.Days > 0 ? string.Format($"{timeSpan.Days:n0} day{{0}}, ", timeSpan.Days != 1 ? "s" : string.Empty) : string.Empty, - timeSpan.Hours > 0 ? string.Format($"{timeSpan.Hours:n0} hour{{0}}, ", timeSpan.Hours != 1 ? "s" : string.Empty) : string.Empty, - timeSpan.Minutes > 0 ? string.Format($"{timeSpan.Minutes:n0} minute{{0}}, ", timeSpan.Minutes != 1 ? "s" : string.Empty) : string.Empty, - timeSpan.Seconds > 0 ? string.Format($"{timeSpan.Seconds:n0} second{{0}}", timeSpan.Seconds != 1 ? "s" : string.Empty) : string.Empty + timeSpan.Days > 0 ? $"{timeSpan.Days:n0}{dayText}, " : string.Empty, + timeSpan.Hours > 0 ? $"{timeSpan.Hours:n0}{hourText}, " : string.Empty, + timeSpan.TotalHours <= skipMinutesAndSecondsAfterHours ? + timeSpan.Minutes > 0 ? $"{timeSpan.Minutes:n0}{minuteText}, " : string.Empty : + string.Empty, + timeSpan.TotalHours <= skipMinutesAndSecondsAfterHours ? + timeSpan.Seconds > 0 ? $"{timeSpan.Seconds:n0}{secondText}" : string.Empty : + string.Empty ).Trim(new[] { ' ', ',' }); } } From e72f60b98a2cffad0414ef85f4b6000c05cafa21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 18 Dec 2023 13:20:22 +0100 Subject: [PATCH 11/16] fix: Skip seconds after 1 hour, skip minutes after 24 hours --- CFLookup/SharedMethods.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CFLookup/SharedMethods.cs b/CFLookup/SharedMethods.cs index e18b72d..c4434d4 100644 --- a/CFLookup/SharedMethods.cs +++ b/CFLookup/SharedMethods.cs @@ -357,7 +357,7 @@ public static string GetProjectNameFromFile(string url) return Path.GetFileName(url); } - public static string ToHumanReadableFormat(this TimeSpan timeSpan, bool shortText = false, double skipMinutesAndSecondsAfterHours = 2.0f) + public static string ToHumanReadableFormat(this TimeSpan timeSpan, bool shortText = false, double skipMinutesAfterHours = 24.0f, double skipSecondsAfterHours = 1.0f) { var secondText = shortText ? "s" : " second" + (timeSpan.Seconds != 1 ? "s" : string.Empty); var minuteText = shortText ? "m" : " minute" + (timeSpan.Minutes != 1 ? "s" : string.Empty); @@ -367,10 +367,10 @@ public static string ToHumanReadableFormat(this TimeSpan timeSpan, bool shortTex return timeSpan.TotalSeconds <= 0 ? "0 seconds" : string.Format("{0}{1}{2}{3}", timeSpan.Days > 0 ? $"{timeSpan.Days:n0}{dayText}, " : string.Empty, timeSpan.Hours > 0 ? $"{timeSpan.Hours:n0}{hourText}, " : string.Empty, - timeSpan.TotalHours <= skipMinutesAndSecondsAfterHours ? + timeSpan.TotalHours <= skipMinutesAfterHours ? timeSpan.Minutes > 0 ? $"{timeSpan.Minutes:n0}{minuteText}, " : string.Empty : string.Empty, - timeSpan.TotalHours <= skipMinutesAndSecondsAfterHours ? + timeSpan.TotalHours <= skipSecondsAfterHours ? timeSpan.Seconds > 0 ? $"{timeSpan.Seconds:n0}{secondText}" : string.Empty : string.Empty ).Trim(new[] { ' ', ',' }); From b89b814bd3894e50952e4762e3eeb3fd9aeba598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Wed, 20 Dec 2023 07:49:11 +0100 Subject: [PATCH 12/16] feat: Find private game mods as well --- CFLookup/Jobs/GetLatestUpdatedModPerGame.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs index 65ef355..2258e01 100644 --- a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs +++ b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs @@ -44,6 +44,20 @@ public static async Task RunAsync(PerformContext context) Mod? latestUpdatedModData = null; CurseForge.APIClient.Models.Files.File? latestUpdatedFileData = null; + var privateGames = new List + { + 83374 + }; + + foreach (var privateGame in privateGames) + { + var game = await cfClient.GetGameAsync(privateGame); + if (game != null && game.Data != null) + { + allGames.Add(game.Data); + } + } + foreach (var game in allGames) { Console.WriteLine($"Starting to check for latest updated mod for {game.Name}"); From b50cf645aa3764136f4ebf37dd867f4f10af82ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Wed, 20 Dec 2023 11:41:11 +0100 Subject: [PATCH 13/16] feat: Add more games to check file processing for --- CFLookup/Jobs/GetLatestUpdatedModPerGame.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs index 2258e01..2f9ff3f 100644 --- a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs +++ b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs @@ -46,7 +46,15 @@ public static async Task RunAsync(PerformContext context) var privateGames = new List { - 83374 + 449, // Skyrim + 540, // 7 Days To Die + 4482, // Subnautica + 4593, // Final Fantasy XV + 4619, // The Last of Us + 4819, // American Truck Simulator + 6351, // Mario Party 3 + 18237, // Staxel + 83374, // ARK }; foreach (var privateGame in privateGames) From e315cfa6c290b811b4a59a3eaa5a940f9e2e1941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Wed, 20 Dec 2023 16:07:45 +0100 Subject: [PATCH 14/16] feat: Even more games to check --- CFLookup/Jobs/GetLatestUpdatedModPerGame.cs | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs index 2f9ff3f..f68d371 100644 --- a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs +++ b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs @@ -54,7 +54,30 @@ public static async Task RunAsync(PerformContext context) 4819, // American Truck Simulator 6351, // Mario Party 3 18237, // Staxel + 66004, // Starfield + 73492, // Kerbal Space Program 2 + 78022, // Minecraft Bedrock + 78023, // Timber and Stone + 78072, // Hometopia + 78101, // Tiny Life + 78103, // art of rally + 78163, // Astro Colony + 78225, // The Anacrusis + 78251, // Kingshunt + 78496, // Hero's Tour + 79630, // GTA-SA + 79805, // CurseForge Demo + 80345, // Dwerve + 81975, // LEAP + 82010, // KSP QA Test Game + 82047, // Oaken + 82164, // Unity SDK Tester + 83357, // River City Girls 2 83374, // ARK + 83375, // Far Cry 6 + 83444, // WorldBox - God Simulator + 83453, // Minecraft Legends + 83981, // Unreal Test Game }; foreach (var privateGame in privateGames) From 47093a2e6d3077eaa76eadee1a90db72a21ecae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Wed, 20 Dec 2023 16:15:43 +0100 Subject: [PATCH 15/16] fix: Check if the latestUpdatedFile contains anything. --- CFLookup/Jobs/GetLatestUpdatedModPerGame.cs | 74 +++++++++++---------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs index f68d371..5b907bc 100644 --- a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs +++ b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs @@ -98,46 +98,48 @@ public static async Task RunAsync(PerformContext context) if (latestUpdatedMod != null && latestUpdatedMod.Pagination.ResultCount > 0) { var mod = latestUpdatedMod.Data.First(); - var latestUpdatedFile = mod.LatestFiles.OrderByDescending(f => f.FileDate).First(); - Console.WriteLine($"Latest updated mod for {game.Name} is {mod.Name} with {mod.DownloadCount} downloads and the latest file was updated {latestUpdatedFile.FileDate}"); - if (lastUpdatedMod < latestUpdatedFile.FileDate) + var latestUpdatedFile = mod.LatestFiles.OrderByDescending(f => f.FileDate).FirstOrDefault(); + if (latestUpdatedFile != null) { - lastUpdatedMod = latestUpdatedFile.FileDate; - latestUpdatedModData = mod; - latestUpdatedFileData = latestUpdatedFile; - } - - await _db.StringSetAsync($"cf-mod-{mod.Id}", JsonSerializer.Serialize(mod), TimeSpan.FromDays(1)); - await _db.StringSetAsync($"cf-file-{latestUpdatedFile.Id}", JsonSerializer.Serialize(latestUpdatedFile), TimeSpan.FromDays(1)); - - var existingGame = await db.ExecuteSingleRowAsync( - "SELECT * FROM fileProcessingStatus WHERE gameId = @gameId", - new SqlParameter("@gameId", game.Id) - ); - - if (existingGame == null) - { - // New game, insert it - await db.ExecuteNonQueryAsync( - "INSERT INTO fileProcessingStatus (last_updated_utc, gameId, modId, fileId) VALUES (@last_updated_utc, @gameId, @modId, @fileId)", - new SqlParameter("@last_updated_utc", latestUpdatedFile.FileDate), - new SqlParameter("@gameId", game.Id), - new SqlParameter("@modId", mod.Id), - new SqlParameter("@fileId", latestUpdatedFile.Id) - ); - } - else - { - // Existing game, update it - await db.ExecuteNonQueryAsync( - "UPDATE fileProcessingStatus SET last_updated_utc = @last_updated_utc, modId = @modId, fileId = @fileId WHERE gameId = @gameId", - new SqlParameter("@last_updated_utc", latestUpdatedFile.FileDate), - new SqlParameter("@modId", mod.Id), - new SqlParameter("@fileId", latestUpdatedFile.Id), + Console.WriteLine($"Latest updated mod for {game.Name} is {mod.Name} with {mod.DownloadCount} downloads and the latest file was updated {latestUpdatedFile.FileDate}"); + if (lastUpdatedMod < latestUpdatedFile.FileDate) + { + lastUpdatedMod = latestUpdatedFile.FileDate; + latestUpdatedModData = mod; + latestUpdatedFileData = latestUpdatedFile; + } + + await _db.StringSetAsync($"cf-mod-{mod.Id}", JsonSerializer.Serialize(mod), TimeSpan.FromDays(1)); + await _db.StringSetAsync($"cf-file-{latestUpdatedFile.Id}", JsonSerializer.Serialize(latestUpdatedFile), TimeSpan.FromDays(1)); + + var existingGame = await db.ExecuteSingleRowAsync( + "SELECT * FROM fileProcessingStatus WHERE gameId = @gameId", new SqlParameter("@gameId", game.Id) ); - } + if (existingGame == null) + { + // New game, insert it + await db.ExecuteNonQueryAsync( + "INSERT INTO fileProcessingStatus (last_updated_utc, gameId, modId, fileId) VALUES (@last_updated_utc, @gameId, @modId, @fileId)", + new SqlParameter("@last_updated_utc", latestUpdatedFile.FileDate), + new SqlParameter("@gameId", game.Id), + new SqlParameter("@modId", mod.Id), + new SqlParameter("@fileId", latestUpdatedFile.Id) + ); + } + else + { + // Existing game, update it + await db.ExecuteNonQueryAsync( + "UPDATE fileProcessingStatus SET last_updated_utc = @last_updated_utc, modId = @modId, fileId = @fileId WHERE gameId = @gameId", + new SqlParameter("@last_updated_utc", latestUpdatedFile.FileDate), + new SqlParameter("@modId", mod.Id), + new SqlParameter("@fileId", latestUpdatedFile.Id), + new SqlParameter("@gameId", game.Id) + ); + } + } } else { From 1f8a6b7fc58417780b75ed1ad45b040bcf4d8007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Wed, 20 Dec 2023 16:44:50 +0100 Subject: [PATCH 16/16] chore: Add info that we couldn't find any updated files for mods --- CFLookup/Jobs/GetLatestUpdatedModPerGame.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs index 5b907bc..cfede64 100644 --- a/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs +++ b/CFLookup/Jobs/GetLatestUpdatedModPerGame.cs @@ -78,6 +78,13 @@ public static async Task RunAsync(PerformContext context) 83444, // WorldBox - God Simulator 83453, // Minecraft Legends 83981, // Unreal Test Game + 84529, // NighspadeTest001 + 84530, // OWITestGame + 84610, // Test01 + 84658, // AI M3 + 84749, // Minecraft + 84801, // stopdeletingmystuffiamtesting + 84810, // Oaken_Testing }; foreach (var privateGame in privateGames) @@ -140,6 +147,10 @@ await db.ExecuteNonQueryAsync( ); } } + else + { + Console.WriteLine($"No updated files found for {game.Name} and mod {mod.Name}"); + } } else {