1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-14 04:03:22 +08:00

Merge pull request #1831 from peppy/fix-import-context-state

Fix errors on import
This commit is contained in:
Dean Herbert 2018-01-03 14:34:05 +09:00 committed by GitHub
commit 494b1893e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,15 +102,26 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
public Func<Storage> GetStableStorage { private get; set; } public Func<Storage> GetStableStorage { private get; set; }
public BeatmapManager(Storage storage, Func<OsuDbContext> context, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null) private void refreshImportContext()
{ {
createContext = context; lock (importContextLock)
{
importContext?.Value?.Dispose();
importContext = new Lazy<OsuDbContext>(() => importContext = new Lazy<OsuDbContext>(() =>
{ {
var c = createContext(); var c = createContext();
c.Database.AutoTransactionsEnabled = false; c.Database.AutoTransactionsEnabled = false;
return c; return c;
}); });
}
}
public BeatmapManager(Storage storage, Func<OsuDbContext> context, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
{
createContext = context;
refreshImportContext();
beatmaps = createBeatmapStore(context); beatmaps = createBeatmapStore(context);
files = new FileStore(context, storage); files = new FileStore(context, storage);
@ -175,13 +186,16 @@ namespace osu.Game.Beatmaps
{ {
e = e.InnerException ?? e; e = e.InnerException ?? e;
Logger.Error(e, $@"Could not import beatmap set ({Path.GetFileName(path)})"); Logger.Error(e, $@"Could not import beatmap set ({Path.GetFileName(path)})");
refreshImportContext();
} }
} }
notification.State = ProgressNotificationState.Completed; notification.State = ProgressNotificationState.Completed;
} }
private readonly Lazy<OsuDbContext> importContext; private readonly object importContextLock = new object();
private Lazy<OsuDbContext> importContext;
/// <summary> /// <summary>
/// Import a beatmap from an <see cref="ArchiveReader"/>. /// Import a beatmap from an <see cref="ArchiveReader"/>.
@ -190,7 +204,7 @@ namespace osu.Game.Beatmaps
public BeatmapSetInfo Import(ArchiveReader archiveReader) public BeatmapSetInfo Import(ArchiveReader archiveReader)
{ {
// let's only allow one concurrent import at a time for now. // let's only allow one concurrent import at a time for now.
lock (importContext) lock (importContextLock)
{ {
var context = importContext.Value; var context = importContext.Value;
@ -315,7 +329,7 @@ namespace osu.Game.Beatmaps
/// <param name="beatmapSet">The beatmap set to delete.</param> /// <param name="beatmapSet">The beatmap set to delete.</param>
public void Delete(BeatmapSetInfo beatmapSet) public void Delete(BeatmapSetInfo beatmapSet)
{ {
lock (importContext) lock (importContextLock)
{ {
var context = importContext.Value; var context = importContext.Value;
@ -378,7 +392,7 @@ namespace osu.Game.Beatmaps
if (beatmapSet.Protected) if (beatmapSet.Protected)
return; return;
lock (importContext) lock (importContextLock)
{ {
var context = importContext.Value; var context = importContext.Value;