diff --git a/Source/ACE.Database/ShardDatabase.cs b/Source/ACE.Database/ShardDatabase.cs index 9d96b3cb43..fb1c69ee17 100644 --- a/Source/ACE.Database/ShardDatabase.cs +++ b/Source/ACE.Database/ShardDatabase.cs @@ -129,6 +129,33 @@ public int GetBiotaCount() return context.Biota.Count(); } + public int GetEstimatedBiotaCount(string dbName) + { + // https://mariadb.com/kb/en/incredibly-slow-count-on-mariadb-mysql/ + + var sql = $"SELECT TABLE_ROWS FROM information_schema.tables" + Environment.NewLine + + $"WHERE TABLE_SCHEMA = '{dbName}'" + Environment.NewLine + + $"AND TABLE_NAME = 'biota';"; + + using (var context = new ShardDbContext()) + { + var connection = context.Database.GetDbConnection(); + connection.Open(); + var command = connection.CreateCommand(); + command.CommandText = sql; + var reader = command.ExecuteReader(); + + var biotaEstimatedCount = 0; + + while (reader.Read()) + { + biotaEstimatedCount = reader.GetFieldValue(0); + } + + return biotaEstimatedCount; + } + } + [Flags] public enum PopulatedCollectionFlags { diff --git a/Source/ACE.Server/Command/Handlers/AdminStatCommands.cs b/Source/ACE.Server/Command/Handlers/AdminStatCommands.cs index 9fa9acb2fb..953b5c4317 100644 --- a/Source/ACE.Server/Command/Handlers/AdminStatCommands.cs +++ b/Source/ACE.Server/Command/Handlers/AdminStatCommands.cs @@ -138,7 +138,8 @@ public static void HandleServerStatus(Session session, params string[] parameter sb.Append($"Total Server Objects: {ServerObjectManager.ServerObjects.Count:N0}{'\n'}"); sb.Append($"World DB Cache Counts - Weenies: {DatabaseManager.World.GetWeenieCacheCount():N0}, LandblockInstances: {DatabaseManager.World.GetLandblockInstancesCacheCount():N0}, PointsOfInterest: {DatabaseManager.World.GetPointsOfInterestCacheCount():N0}, Cookbooks: {DatabaseManager.World.GetCookbookCacheCount():N0}, Spells: {DatabaseManager.World.GetSpellCacheCount():N0}, Encounters: {DatabaseManager.World.GetEncounterCacheCount():N0}, Events: {DatabaseManager.World.GetEventsCacheCount():N0}{'\n'}"); - sb.Append($"Shard DB Counts - Biotas: {DatabaseManager.Shard.BaseDatabase.GetBiotaCount():N0}{'\n'}"); + //sb.Append($"Shard DB Counts - Biotas: {DatabaseManager.Shard.BaseDatabase.GetBiotaCount():N0}{'\n'}"); + sb.Append($"Shard DB Counts - Biotas: ~{DatabaseManager.Shard.BaseDatabase.GetEstimatedBiotaCount(ConfigManager.Config.MySql.Shard.Database):N0}{'\n'}"); if (DatabaseManager.Shard.BaseDatabase is ShardDatabaseWithCaching shardDatabaseWithCaching) { var biotaIds = shardDatabaseWithCaching.GetBiotaCacheKeys(); @@ -155,7 +156,7 @@ public static void HandleServerStatus(Session session, params string[] parameter CommandHandlerHelper.WriteOutputInfo(session, $"{sb}"); } - // serverstatus + // serverperformance [CommandHandler("serverperformance", AccessLevel.Advocate, CommandHandlerFlag.None, 0, "Displays a summary of server performance statistics")] public static void HandleServerPerformance(Session session, params string[] parameters) {