1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-30 06:52:53 +08:00

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

View File

@ -165,6 +165,8 @@ namespace osu.Game.Beatmaps
private readonly object importLock = new object(); private readonly object importLock = new object();
private OsuDbContext importContext;
/// <summary> /// <summary>
/// Import a beatmap from an <see cref="ArchiveReader"/>. /// Import a beatmap from an <see cref="ArchiveReader"/>.
/// </summary> /// </summary>
@ -174,7 +176,7 @@ namespace osu.Game.Beatmaps
// 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 (importLock) lock (importLock)
{ {
var context = createContext(); var context = importContext ?? (importContext = createContext());
context.Database.AutoTransactionsEnabled = false; context.Database.AutoTransactionsEnabled = false;
@ -190,9 +192,9 @@ namespace osu.Game.Beatmaps
{ {
iBeatmaps.Add(set); iBeatmaps.Add(set);
context.SaveChanges(); context.SaveChanges();
transaction.Commit();
} }
transaction.Commit();
return set; return set;
} }
} }