Fix LBP1 minimum players

This commit is contained in:
jvyden 2021-10-31 18:28:25 -04:00
parent 79be3e175b
commit 54a61570bd
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 26 additions and 0 deletions

View file

@ -96,6 +96,12 @@ namespace LBPUnion.ProjectLighthouse.Controllers
slot.FirstUploaded = TimeHelper.UnixTimeMilliseconds();
slot.LastUpdated = TimeHelper.UnixTimeMilliseconds();
if (slot.MinimumPlayers == 0 || slot.MaximumPlayers == 0)
{
slot.MinimumPlayers = 1;
slot.MaximumPlayers = 4;
}
this.database.Slots.Add(slot);
await this.database.SaveChangesAsync();

View file

@ -45,6 +45,9 @@ namespace LBPUnion.ProjectLighthouse
Logger.Log("Fixing broken timestamps...", LoggerLevelDatabase.Instance);
FixTimestamps(database);
Logger.Log("Fixing old LBP1 MinimumPlayers columns", LoggerLevelDatabase.Instance);
FixMinimumPlayers(database);
stopwatch.Stop();
Logger.Log($"Ready! Startup took {stopwatch.ElapsedMilliseconds}ms. Passing off control to ASP.NET...", LoggerLevelStartup.Instance);
@ -79,6 +82,23 @@ namespace LBPUnion.ProjectLighthouse
Logger.Log($"Fixing timestamps took {stopwatch.ElapsedMilliseconds}ms.", LoggerLevelDatabase.Instance);
}
public static void FixMinimumPlayers(Database database)
{
Stopwatch stopwatch = new();
stopwatch.Start();
foreach (Slot slot in database.Slots.Where(s => s.MinimumPlayers == 0))
{
slot.MinimumPlayers = 1;
slot.MaximumPlayers = 4;
}
database.SaveChanges();
stopwatch.Stop();
Logger.Log($"Fixing minimum players took {stopwatch.ElapsedMilliseconds}ms.", LoggerLevelDatabase.Instance);
}
public static IHostBuilder CreateHostBuilder(string[] args)
=> Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults