Improve performance of imports by keeping a context hot

This commit is contained in:
Dean Herbert 2017-10-17 20:29:47 +09:00
parent 4e8019b313
commit 4193004fbf
1 changed files with 4 additions and 2 deletions

View File

@ -165,6 +165,8 @@ public void Import(params string[] paths)
private readonly object importLock = new object();
private OsuDbContext importContext;
/// <summary>
/// Import a beatmap from an <see cref="ArchiveReader"/>.
/// </summary>
@ -174,7 +176,7 @@ public BeatmapSetInfo Import(ArchiveReader archiveReader)
// let's only allow one concurrent import at a time for now.
lock (importLock)
{
var context = createContext();
var context = importContext ?? (importContext = createContext());
context.Database.AutoTransactionsEnabled = false;
@ -190,9 +192,9 @@ public BeatmapSetInfo Import(ArchiveReader archiveReader)
{
iBeatmaps.Add(set);
context.SaveChanges();
transaction.Commit();
}
transaction.Commit();
return set;
}
}