Merge branch 'master' into fix-invalid-operation

This commit is contained in:
Dan Balasescu 2018-07-25 14:35:36 +09:00 committed by GitHub
commit affecccabc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -5,6 +5,7 @@
using System.Linq;
using System.Threading;
using Microsoft.EntityFrameworkCore.Storage;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Platform;
namespace osu.Game.Database
@ -115,7 +116,11 @@ private void usageCompleted(DatabaseWriteUsage usage)
}
}
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))
{
@ -127,8 +132,6 @@ public void ResetDatabase()
lock (writeLock)
{
recycleThreadContexts();
GC.Collect();
GC.WaitForPendingFinalizers();
storage.DeleteDatabase(database_name);
}
}

View File

@ -224,7 +224,7 @@ private void runMigrations()
// todo: we probably want a better (non-destructive) migrations/recovery process at a later point than this.
contextFactory.ResetDatabase();
Logger.Log("Database purged successfully.", LoggingTarget.Database, LogLevel.Important);
Logger.Log("Database purged successfully.", LoggingTarget.Database);
// only run once more, then hard bail.
using (var db = contextFactory.GetForWrite(false))