mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 11:27:24 +08:00
Fix resetting database failing due to incorrect disposal logic
This commit is contained in:
parent
9dc55688d2
commit
b38da34da9
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.EntityFrameworkCore.Storage;
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
@ -115,7 +116,11 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recycleThreadContexts() => threadContexts = new ThreadLocal<OsuDbContext>(CreateContext);
|
private void recycleThreadContexts()
|
||||||
|
{
|
||||||
|
threadContexts?.Values.ForEach(c => c.Dispose());
|
||||||
|
threadContexts = new ThreadLocal<OsuDbContext>(CreateContext, true);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual OsuDbContext CreateContext() => new OsuDbContext(storage.GetDatabaseConnectionString(database_name))
|
protected virtual OsuDbContext CreateContext() => new OsuDbContext(storage.GetDatabaseConnectionString(database_name))
|
||||||
{
|
{
|
||||||
@ -127,8 +132,6 @@ namespace osu.Game.Database
|
|||||||
lock (writeLock)
|
lock (writeLock)
|
||||||
{
|
{
|
||||||
recycleThreadContexts();
|
recycleThreadContexts();
|
||||||
GC.Collect();
|
|
||||||
GC.WaitForPendingFinalizers();
|
|
||||||
storage.DeleteDatabase(database_name);
|
storage.DeleteDatabase(database_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user