mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 10:08:39 +00:00
Add fix timestamps step on startup
This commit is contained in:
parent
830e9da4ea
commit
73c68c92fe
1 changed files with 49 additions and 15 deletions
|
@ -1,7 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using Kettu;
|
using Kettu;
|
||||||
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
@ -14,8 +18,8 @@ namespace LBPUnion.ProjectLighthouse {
|
||||||
public static class Program {
|
public static class Program {
|
||||||
public static void Main(string[] args) {
|
public static void Main(string[] args) {
|
||||||
// Log startup time
|
// Log startup time
|
||||||
Stopwatch startupStopwatch = new();
|
Stopwatch stopwatch = new();
|
||||||
startupStopwatch.Start();
|
stopwatch.Start();
|
||||||
|
|
||||||
// Setup logging
|
// Setup logging
|
||||||
|
|
||||||
|
@ -29,24 +33,54 @@ namespace LBPUnion.ProjectLighthouse {
|
||||||
bool dbConnected = ServerSettings.DbConnected;
|
bool dbConnected = ServerSettings.DbConnected;
|
||||||
Logger.Log(dbConnected ? "Connected to the database." : "Database unavailable! Exiting.", LoggerLevelStartup.Instance);
|
Logger.Log(dbConnected ? "Connected to the database." : "Database unavailable! Exiting.", LoggerLevelStartup.Instance);
|
||||||
|
|
||||||
if(dbConnected) {
|
if(!dbConnected) Environment.Exit(1);
|
||||||
Stopwatch migrationStopwatch = new();
|
using Database database = new();
|
||||||
migrationStopwatch.Start();
|
|
||||||
|
Logger.Log("Migrating database...", LoggerLevelDatabase.Instance);
|
||||||
Logger.Log("Migrating database...", LoggerLevelDatabase.Instance);
|
MigrateDatabase(database);
|
||||||
using Database database = new();
|
|
||||||
database.Database.Migrate();
|
|
||||||
|
|
||||||
migrationStopwatch.Stop();
|
|
||||||
Logger.Log($"Migration took {migrationStopwatch.ElapsedMilliseconds}ms.", LoggerLevelDatabase.Instance);
|
|
||||||
} else Environment.Exit(1);
|
|
||||||
|
|
||||||
startupStopwatch.Stop();
|
|
||||||
Logger.Log($"Ready! Startup took {startupStopwatch.ElapsedMilliseconds}ms. Passing off control to ASP.NET...", LoggerLevelStartup.Instance);
|
Logger.Log("Fixing broken timestamps...", LoggerLevelDatabase.Instance);
|
||||||
|
FixTimestamps(database);
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
Logger.Log($"Ready! Startup took {stopwatch.ElapsedMilliseconds}ms. Passing off control to ASP.NET...", LoggerLevelStartup.Instance);
|
||||||
|
|
||||||
CreateHostBuilder(args).Build().Run();
|
CreateHostBuilder(args).Build().Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void MigrateDatabase(Database database) {
|
||||||
|
Stopwatch stopwatch = new();
|
||||||
|
stopwatch.Start();
|
||||||
|
|
||||||
|
database.Database.Migrate();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
Logger.Log($"Migration took {stopwatch.ElapsedMilliseconds}ms.", LoggerLevelDatabase.Instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void FixTimestamps(Database database) {
|
||||||
|
Stopwatch stopwatch = new();
|
||||||
|
stopwatch.Start();
|
||||||
|
|
||||||
|
foreach(Slot slot in database.Slots.Where(s => s.FirstUploaded == 0)) {
|
||||||
|
slot.FirstUploaded = TimeHelper.UnixTimeMilliseconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(Slot slot in database.Slots.Where(s => s.LastUpdated == 0)) {
|
||||||
|
slot.LastUpdated = TimeHelper.UnixTimeMilliseconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(Comment comment in database.Comments.Where(c => c.Timestamp == 0)) {
|
||||||
|
comment.Timestamp = TimeHelper.UnixTimeMilliseconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
database.SaveChanges();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
Logger.Log($"Fixing timestamps took {stopwatch.ElapsedMilliseconds}ms.", LoggerLevelDatabase.Instance);
|
||||||
|
}
|
||||||
|
|
||||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||||
Host.CreateDefaultBuilder(args)
|
Host.CreateDefaultBuilder(args)
|
||||||
.ConfigureWebHostDefaults(webBuilder => {
|
.ConfigureWebHostDefaults(webBuilder => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue