Here's bancho's implementation of this for reference. The important part is the UPDATE statement (the INSERT one is not relevant for the newer implemetation) but I've included the whole stats method for context.
private static bool isUpdatingStats;
private static void updateStats()
{
if (isUpdatingStats || !ReportClientCounts) return;
var countOsu = UserManager.CountOsu;
// avoid reporting low stats by accident
if (countOsu < 32) return;
isUpdatingStats = true;
RunThread(() =>
{
try
{
Database.RunNonQueryLowPriority(
"INSERT INTO osu_banchostats (users_irc, users_osu, multiplayer_games) VALUES (@irc, @osu, @mp)",
new MySqlParameter("irc", UserManager.CountIrc),
new MySqlParameter("osu", countOsu),
new MySqlParameter("mp", Lobby.Matches.Count));
SortedDictionary<string, int> versionCounts = new SortedDictionary<string, int>();
foreach (Client c in UserManager.Clients)
{
NetClient nc = c as NetClient;
if (nc == null) continue;
string version = Regex.Replace(nc.Version, "[^0-9.]", string.Empty);
if (versionCounts.ContainsKey(version))
versionCounts[version]++;
else
versionCounts[version] = 1;
}
foreach (var v in versionCounts)
{
Database.RunNonQueryLowPriority("UPDATE osu_builds SET users = @users WHERE version = @version",
new MySqlParameter("users", v.Value),
new MySqlParameter("version", v.Key)
);
}
}
catch (Exception e)
{
Bacon.WriteLine("Database connection failed!");
Bacon.WriteLine(e.ToString());
}
isUpdatingStats = false;
});
}
As brought up in https://github.com/ppy/osu/discussions/18590#discussioncomment-2932477, we need to report counts of users per release so it can be shown in places like the changelog header.
Here's bancho's implementation of this for reference. The important part is the
UPDATE
statement (theINSERT
one is not relevant for the newer implemetation) but I've included the whole stats method for context.