mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Add database statistics to GlobalStatistics
This commit is contained in:
@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Statistics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.IO;
|
||||
@ -34,6 +35,8 @@ namespace osu.Game.Database
|
||||
|
||||
private static readonly Lazy<OsuDbLoggerFactory> logger = new Lazy<OsuDbLoggerFactory>(() => new OsuDbLoggerFactory());
|
||||
|
||||
private static readonly GlobalStatistic<int> contexts = GlobalStatistics.Get<int>("Database", "Contexts");
|
||||
|
||||
static OsuDbContext()
|
||||
{
|
||||
// required to initialise native SQLite libraries on some platforms.
|
||||
@ -76,6 +79,8 @@ namespace osu.Game.Database
|
||||
connection.Close();
|
||||
throw;
|
||||
}
|
||||
|
||||
contexts.Value++;
|
||||
}
|
||||
|
||||
~OsuDbContext()
|
||||
@ -85,6 +90,20 @@ namespace osu.Game.Database
|
||||
Dispose();
|
||||
}
|
||||
|
||||
private bool isDisposed;
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (isDisposed) return;
|
||||
|
||||
isDisposed = true;
|
||||
|
||||
base.Dispose();
|
||||
|
||||
contexts.Value--;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
|
Reference in New Issue
Block a user