Remove redundant checks for MongoId
This commit is contained in:
@@ -182,72 +182,4 @@ public class DatabaseService(
|
||||
|
||||
return databaseServer.GetTables().Templates?.LocationServices!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates that the database doesn't contain invalid ID data
|
||||
/// </summary>
|
||||
public void ValidateDatabase()
|
||||
{
|
||||
var start = Stopwatch.StartNew();
|
||||
|
||||
_isDataValid =
|
||||
ValidateTable(GetQuests(), "quest")
|
||||
&& ValidateTable(GetTraders(), "trader")
|
||||
&& ValidateTable(GetItems(), "item")
|
||||
&& ValidateTable(GetCustomization(), "customization");
|
||||
|
||||
if (!_isDataValid)
|
||||
{
|
||||
logger.Error(serverLocalisationService.GetText("database-invalid_data"));
|
||||
}
|
||||
|
||||
start.Stop();
|
||||
if (logger.IsLogEnabled(LogLevel.Debug))
|
||||
{
|
||||
logger.Debug($"ID validation took: {start.ElapsedMilliseconds}ms");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate that the given table only contains valid MongoIDs
|
||||
/// </summary>
|
||||
/// <param name="table"> Table to validate for MongoIDs</param>
|
||||
/// <param name="tableType"> The type of table, used in output message </param>
|
||||
/// <returns> True if the table only contains valid data </returns>
|
||||
private bool ValidateTable<T>(Dictionary<string, T> table, string tableType)
|
||||
{
|
||||
foreach (var keyValuePair in table)
|
||||
{
|
||||
if (!keyValuePair.Key.IsValidMongoId())
|
||||
{
|
||||
logger.Error($"Invalid {tableType} ID: '{keyValuePair.Key}'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ValidateTable<T>(Dictionary<MongoId, T> table, string tableType)
|
||||
{
|
||||
foreach (var keyValuePair in table)
|
||||
{
|
||||
if (!keyValuePair.Key.IsValidMongoId())
|
||||
{
|
||||
logger.Error($"Invalid {tableType} ID: '{keyValuePair.Key}'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the database is valid
|
||||
/// </summary>
|
||||
/// <returns> True if the database contains valid data, false otherwise </returns>
|
||||
public bool IsDatabaseValid()
|
||||
{
|
||||
return _isDataValid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,15 +42,6 @@ public class PostDbLoadService(
|
||||
// add items gets left out,causing warnings
|
||||
itemBaseClassService.HydrateItemBaseClassCache();
|
||||
|
||||
// Validate that only mongoIds exist in items, quests, and traders
|
||||
// Kill the startup if not.
|
||||
// TODO: We can probably remove this in a couple versions
|
||||
databaseService.ValidateDatabase();
|
||||
if (!databaseService.IsDatabaseValid())
|
||||
{
|
||||
throw new Exception("Server start failure, database invalid");
|
||||
}
|
||||
|
||||
AddCustomLooseLootPositions();
|
||||
|
||||
MergeCustomAchievements();
|
||||
|
||||
@@ -78,15 +78,6 @@ public class App(
|
||||
{
|
||||
while (!appLifeTime.ApplicationStopping.IsCancellationRequested)
|
||||
{
|
||||
// If the server has failed to start, skip any update calls
|
||||
if (!databaseService.IsDatabaseValid())
|
||||
{
|
||||
await Task.Delay(5000, appLifeTime.ApplicationStopping);
|
||||
|
||||
// Skip forward to the next loop
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var updateable in onUpdateComponents)
|
||||
{
|
||||
var updateableName = updateable.GetType().FullName;
|
||||
|
||||
Reference in New Issue
Block a user