1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00

Use one DbContext with configured CommandTimeout for all stores

This commit is contained in:
TocoToucan 2017-10-08 18:18:28 +03:00
parent 887aa7496b
commit 5d27c66efa

View File

@ -83,7 +83,7 @@ namespace osu.Game
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) =>
dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
//private OsuDbContext dbContext;
private OsuDbContext dbContext;
private OsuDbContext createDbContext()
{
@ -96,6 +96,7 @@ namespace osu.Game
command.CommandText = "PRAGMA journal_mode=WAL;";
command.ExecuteNonQuery();
}
context.Database.SetCommandTimeout(new TimeSpan(TimeSpan.TicksPerSecond * 10));
return context;
}
@ -105,8 +106,7 @@ namespace osu.Game
dependencies.Cache(this);
dependencies.Cache(LocalConfig);
using (var dbContext = createDbContext())
dbContext = createDbContext();
if (dbContext.Database.GetPendingMigrations().Any())
dbContext.Database.Migrate();
@ -116,11 +116,11 @@ namespace osu.Game
Token = LocalConfig.Get<string>(OsuSetting.Token)
});
dependencies.Cache(RulesetStore = new RulesetStore(createDbContext()));
dependencies.Cache(FileStore = new FileStore(createDbContext(), Host.Storage));
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, createDbContext(), RulesetStore, API, Host));
dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, createDbContext(), Host, BeatmapManager, RulesetStore));
dependencies.Cache(KeyBindingStore = new KeyBindingStore(createDbContext(), RulesetStore));
dependencies.Cache(RulesetStore = new RulesetStore(dbContext));
dependencies.Cache(FileStore = new FileStore(dbContext, Host.Storage));
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, dbContext, RulesetStore, API, Host));
dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, dbContext, Host, BeatmapManager, RulesetStore));
dependencies.Cache(KeyBindingStore = new KeyBindingStore(dbContext, RulesetStore));
dependencies.Cache(new OsuColour());
//this completely overrides the framework default. will need to change once we make a proper FontStore.
@ -247,7 +247,7 @@ namespace osu.Game
LocalConfig.Save();
}
//dbContext?.Dispose();
dbContext?.Dispose();
base.Dispose(isDisposing);
}