diff --git a/Source/ACE.Database/DatabaseManager.cs b/Source/ACE.Database/DatabaseManager.cs index 0c1288140b..50cee2c1bd 100644 --- a/Source/ACE.Database/DatabaseManager.cs +++ b/Source/ACE.Database/DatabaseManager.cs @@ -1,4 +1,7 @@ using System; +using System.Collections.Concurrent; + +using Microsoft.EntityFrameworkCore; using log4net; @@ -69,5 +72,17 @@ public static void Stop() if (serializedShardDb != null) serializedShardDb.Stop(); } + + private static readonly ConcurrentDictionary cachedServerVersions = new(); + + public static ServerVersion CachedServerVersionAutoDetect(string database, string connectionString) + { + if (!cachedServerVersions.TryGetValue(database, out ServerVersion serverVersion)) + { + serverVersion = ServerVersion.AutoDetect(connectionString); + cachedServerVersions[database] = serverVersion; + } + return serverVersion; + } } } diff --git a/Source/ACE.Database/Models/Auth/AuthDbContext.cs b/Source/ACE.Database/Models/Auth/AuthDbContext.cs index 134fe9aeb7..560415adf9 100644 --- a/Source/ACE.Database/Models/Auth/AuthDbContext.cs +++ b/Source/ACE.Database/Models/Auth/AuthDbContext.cs @@ -28,7 +28,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) var connectionString = $"server={config.Host};port={config.Port};user={config.Username};password={config.Password};database={config.Database};{config.ConnectionOptions}"; - optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), builder => + optionsBuilder.UseMySql(connectionString, DatabaseManager.CachedServerVersionAutoDetect(config.Database, connectionString), builder => { builder.EnableRetryOnFailure(10); }); diff --git a/Source/ACE.Database/Models/Shard/ShardDbContext.cs b/Source/ACE.Database/Models/Shard/ShardDbContext.cs index bceb8b1374..58b3919283 100644 --- a/Source/ACE.Database/Models/Shard/ShardDbContext.cs +++ b/Source/ACE.Database/Models/Shard/ShardDbContext.cs @@ -104,7 +104,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) var connectionString = $"server={config.Host};port={config.Port};user={config.Username};password={config.Password};database={config.Database};{config.ConnectionOptions}"; - optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), builder => + optionsBuilder.UseMySql(connectionString, DatabaseManager.CachedServerVersionAutoDetect(config.Database, connectionString), builder => { builder.EnableRetryOnFailure(10); }); diff --git a/Source/ACE.Database/Models/World/WorldDbContext.cs b/Source/ACE.Database/Models/World/WorldDbContext.cs index 38a4f1ff48..3d112ca388 100644 --- a/Source/ACE.Database/Models/World/WorldDbContext.cs +++ b/Source/ACE.Database/Models/World/WorldDbContext.cs @@ -132,7 +132,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) var connectionString = $"server={config.Host};port={config.Port};user={config.Username};password={config.Password};database={config.Database};{config.ConnectionOptions}"; - optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), builder => + optionsBuilder.UseMySql(connectionString, DatabaseManager.CachedServerVersionAutoDetect(config.Database, connectionString), builder => { builder.EnableRetryOnFailure(10); });