diff --git a/gaseous-server/Classes/Maintenance.cs b/gaseous-server/Classes/Maintenance.cs new file mode 100644 index 00000000..8b9c3f1b --- /dev/null +++ b/gaseous-server/Classes/Maintenance.cs @@ -0,0 +1,69 @@ +using System; +using System.Data; +using gaseous_server.Models; +using gaseous_tools; +using Microsoft.VisualStudio.Web.CodeGeneration; + +namespace gaseous_server.Classes +{ + public class Maintenance + { + const int MaxFileAge = 30; + + public static void RunMaintenance() + { + // delete files and directories older than 7 days in PathsToClean + List PathsToClean = new List(); + PathsToClean.Add(Config.LibraryConfiguration.LibraryUploadDirectory); + PathsToClean.Add(Config.LibraryConfiguration.LibraryTempDirectory); + + foreach (string PathToClean in PathsToClean) + { + Logging.Log(Logging.LogType.Information, "Maintenance", "Removing files older than " + MaxFileAge + " days from " + PathToClean); + + // get content + // files first + foreach (string filePath in Directory.GetFiles(PathToClean)) + { + FileInfo fileInfo = new FileInfo(filePath); + if (fileInfo.LastWriteTimeUtc.AddDays(MaxFileAge) < DateTime.UtcNow) + { + Logging.Log(Logging.LogType.Warning, "Maintenance", "Deleting file " + filePath); + File.Delete(filePath); + } + } + + // now directories + foreach (string dirPath in Directory.GetDirectories(PathToClean)) + { + DirectoryInfo directoryInfo = new DirectoryInfo(dirPath); + if (directoryInfo.LastWriteTimeUtc.AddDays(MaxFileAge) < DateTime.UtcNow) + { + Logging.Log(Logging.LogType.Warning, "Maintenance", "Deleting directory " + directoryInfo); + Directory.Delete(dirPath, true); + } + } + } + + Logging.Log(Logging.LogType.Information, "Maintenance", "Optimising database tables"); + Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); + string sql = "SHOW TABLES;"; + DataTable tables = db.ExecuteCMD(sql); + + foreach (DataRow row in tables.Rows) + { + sql = "OPTIMIZE TABLE " + row[0].ToString(); + DataTable response = db.ExecuteCMD(sql); + foreach (DataRow responseRow in response.Rows) + { + string retVal = ""; + for (int i = 0; i < responseRow.ItemArray.Length; i++) + { + retVal += responseRow.ItemArray[i] + "; "; + } + Logging.Log(Logging.LogType.Information, "Maintenance", "Optimizse table " + row[0].ToString() + ": " + retVal); + } + } + } + } +} \ No newline at end of file diff --git a/gaseous-server/ProcessQueue.cs b/gaseous-server/ProcessQueue.cs index 6a0ee15c..5c5f76bc 100644 --- a/gaseous-server/ProcessQueue.cs +++ b/gaseous-server/ProcessQueue.cs @@ -164,6 +164,11 @@ public void Execute() gaseous_tools.DatabaseMigration.UpgradeScriptBackgroundTasks(); break; + case QueueItemType.Maintainer: + Logging.Log(Logging.LogType.Debug, "Timered Event", "Starting Maintenance"); + Classes.Maintenance.RunMaintenance(); + break; + } } catch (Exception ex) @@ -243,7 +248,12 @@ public enum QueueItemType /// /// Performs and post database upgrade scripts that can be processed as a background task /// - BackgroundDatabaseUpgrade + BackgroundDatabaseUpgrade, + + /// + /// Performs a clean up of old files, and optimises the database + /// + Maintainer } public enum QueueItemState diff --git a/gaseous-server/Program.cs b/gaseous-server/Program.cs index b58b054c..e3652ac9 100644 --- a/gaseous-server/Program.cs +++ b/gaseous-server/Program.cs @@ -48,6 +48,16 @@ Config.SetSetting("API Key", APIKey.ToString()); } +// clean up storage +if (Directory.Exists(Config.LibraryConfiguration.LibraryTempDirectory)) +{ + Directory.Delete(Config.LibraryConfiguration.LibraryTempDirectory, true); +} +if (Directory.Exists(Config.LibraryConfiguration.LibraryUploadDirectory)) +{ + Directory.Delete(Config.LibraryConfiguration.LibraryUploadDirectory, true); +} + // kick off any delayed upgrade tasks // run 1002 background updates in the background on every start DatabaseMigration.BackgroundUpgradeTargetSchemaVersions.Add(1002); @@ -229,7 +239,14 @@ ProcessQueue.QueueItemType.LibraryScan }) ); - +ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem( + ProcessQueue.QueueItemType.Maintainer, + 10080, + new List + { + ProcessQueue.QueueItemType.All + }) + ); Logging.WriteToDiskOnly = false; diff --git a/gaseous-server/wwwroot/styles/style.css b/gaseous-server/wwwroot/styles/style.css index 16d0e87f..d99eeeab 100644 --- a/gaseous-server/wwwroot/styles/style.css +++ b/gaseous-server/wwwroot/styles/style.css @@ -101,6 +101,7 @@ h3 { padding: 0px; margin: 0px; display: flex; + z-index: 50; } #banner_icon:hover { @@ -198,7 +199,9 @@ h3 { } .filter_panel_box { + position: relative; padding: 10px; + z-index: -1; } input[type='text'], input[type='number'] { @@ -268,6 +271,7 @@ input[id='filter_panel_userrating_max'] { display: flex; position: relative; padding: 3px; + z-index: -1; } .filter_panel_item_checkbox {