Just use count(id) for /sinfo on both backend, closes #255

In the test SQLite database with 800,000 players there was a 2-3 millisecond difference. So not worth it.
This commit is contained in:
UnknownShadow200 2017-09-21 18:15:51 +10:00
parent 79de17943c
commit 774040e9d7

View File

@ -62,21 +62,9 @@ namespace MCGalaxy.Commands.Info {
} }
static int GetPlayerCount() { static int GetPlayerCount() {
// Use fast path if possible TODO: fast path for mysql using (DataTable table = Database.Backend.GetRows("Players", "COUNT(id)")) {
int count = 0; return int.Parse(table.Rows[0]["COUNT(id)"].ToString());
if (!ServerConfig.UseMySQL) {
DataTable maxTable = Database.Backend.GetRows("Players", "MAX(_ROWID_)", "LIMIT 1");
if (maxTable.Rows.Count > 0) {
string row = maxTable.Rows[0]["MAX(_ROWID_)"].ToString();
maxTable.Dispose();
if (int.TryParse(row, out count) && count > 0) return count;
}
} }
DataTable table = Database.Backend.GetRows("Players", "COUNT(id)");
count = int.Parse(table.Rows[0]["COUNT(id)"].ToString());
table.Dispose();
return count;
} }
void ShowServerStats(Player p) { void ShowServerStats(Player p) {