mirror of
https://github.com/ppy/osu
synced 2024-12-16 20:05:41 +00:00
Merge branch 'master' into fix-missing-sqlite
This commit is contained in:
commit
d42371b8d4
@ -1 +1 @@
|
||||
Subproject commit 383a8da7bc45af498288b4b72c72a048a0996e74
|
||||
Subproject commit 26f3091dcaf47e3b355b7f7ad83b292621d7d6b5
|
@ -7,7 +7,6 @@ using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.IO.Network;
|
||||
using FileWebRequest = osu.Framework.IO.Network.FileWebRequest;
|
||||
@ -391,8 +390,8 @@ namespace osu.Desktop.Deploy
|
||||
|
||||
public static void AuthenticatedBlockingPerform(this WebRequest r)
|
||||
{
|
||||
r.AddHeader("Authorization", $"token {GitHubAccessToken}");
|
||||
r.BlockingPerform();
|
||||
r.Headers.Add("Authorization", $"token {GitHubAccessToken}");
|
||||
r.Perform();
|
||||
}
|
||||
}
|
||||
|
||||
@ -402,12 +401,7 @@ namespace osu.Desktop.Deploy
|
||||
{
|
||||
}
|
||||
|
||||
protected override HttpWebRequest CreateWebRequest(string requestString = null)
|
||||
{
|
||||
var req = base.CreateWebRequest(requestString);
|
||||
req.Accept = "application/octet-stream";
|
||||
return req;
|
||||
}
|
||||
protected override string Accept => "application/octet-stream";
|
||||
}
|
||||
|
||||
internal class ReleaseLine
|
||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
private const string osz_path = @"../../../osu-resources/osu.Game.Resources/Beatmaps/241526 Soleily - Renatus.osz";
|
||||
|
||||
//[Test]
|
||||
[Test]
|
||||
public void TestImportWhenClosed()
|
||||
{
|
||||
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||
@ -40,14 +40,16 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
}
|
||||
}
|
||||
|
||||
//[Test]
|
||||
[Test]
|
||||
[NonParallelizable]
|
||||
[Ignore("Binding IPC on Appveyor isn't working (port in use). Need to figure out why")]
|
||||
public void TestImportOverIPC()
|
||||
{
|
||||
using (HeadlessGameHost host = new HeadlessGameHost("host", true))
|
||||
using (HeadlessGameHost client = new HeadlessGameHost("client", true))
|
||||
{
|
||||
Assert.IsTrue(host.IsPrimaryInstance);
|
||||
Assert.IsTrue(!client.IsPrimaryInstance);
|
||||
Assert.IsFalse(client.IsPrimaryInstance);
|
||||
|
||||
var osu = loadOsu(host);
|
||||
|
||||
@ -65,7 +67,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
}
|
||||
}
|
||||
|
||||
//[Test]
|
||||
[Test]
|
||||
public void TestImportWhenFileOpen()
|
||||
{
|
||||
using (HeadlessGameHost host = new HeadlessGameHost("TestImportWhenFileOpen"))
|
||||
@ -100,6 +102,10 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
|
||||
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
||||
|
||||
// this is a temporary workaround for database transaction clashes.
|
||||
// see https://github.com/aspnet/EntityFrameworkCore/issues/9994 for more information.
|
||||
Thread.Sleep(1000);
|
||||
|
||||
return osu;
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
var context = importContext.Value;
|
||||
|
||||
using (var transaction = context.Database.BeginTransaction())
|
||||
using (var transaction = context.BeginTransaction())
|
||||
{
|
||||
// create local stores so we can isolate and thread safely, and share a context/transaction.
|
||||
var iFiles = new FileStore(() => context, storage);
|
||||
@ -198,7 +198,7 @@ namespace osu.Game.Beatmaps
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
context.SaveChanges(transaction);
|
||||
return set;
|
||||
}
|
||||
}
|
||||
@ -295,7 +295,7 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
var context = importContext.Value;
|
||||
|
||||
using (var transaction = context.Database.BeginTransaction())
|
||||
using (var transaction = context.BeginTransaction())
|
||||
{
|
||||
context.ChangeTracker.AutoDetectChangesEnabled = false;
|
||||
|
||||
@ -313,9 +313,7 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
|
||||
context.ChangeTracker.AutoDetectChangesEnabled = true;
|
||||
context.SaveChanges();
|
||||
|
||||
transaction.Commit();
|
||||
context.SaveChanges(transaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,8 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
new ConstrainedIconContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Icon = beatmap.Ruleset.CreateInstance().CreateIcon()
|
||||
// the null coalesce here is only present to make unit tests work (ruleset dlls aren't copied correctly for testing at the moment)
|
||||
Icon = beatmap.Ruleset?.CreateInstance().CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.fa_question_circle_o }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
|
||||
@ -11,12 +12,26 @@ namespace osu.Game.Database
|
||||
{
|
||||
protected readonly Storage Storage;
|
||||
|
||||
protected readonly Func<OsuDbContext> GetContext;
|
||||
/// <summary>
|
||||
/// Create a new <see cref="OsuDbContext"/> instance (separate from the shared context via <see cref="GetContext"/> for performing isolated operations.
|
||||
/// </summary>
|
||||
protected readonly Func<OsuDbContext> CreateContext;
|
||||
|
||||
protected DatabaseBackedStore(Func<OsuDbContext> getContext, Storage storage = null)
|
||||
private readonly ThreadLocal<OsuDbContext> queryContext;
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a shared context for performing lookups (or write operations on the update thread, for now).
|
||||
/// </summary>
|
||||
protected OsuDbContext GetContext() => queryContext.Value;
|
||||
|
||||
protected DatabaseBackedStore(Func<OsuDbContext> createContext, Storage storage = null)
|
||||
{
|
||||
CreateContext = createContext;
|
||||
|
||||
// todo: while this seems to work quite well, we need to consider that contexts could enter a state where they are never cleaned up.
|
||||
queryContext = new ThreadLocal<OsuDbContext>(CreateContext);
|
||||
|
||||
Storage = storage;
|
||||
GetContext = getContext;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using osu.Framework.Logging;
|
||||
@ -23,6 +24,7 @@ namespace osu.Game.Database
|
||||
public DbSet<DatabasedKeyBinding> DatabasedKeyBinding { get; set; }
|
||||
public DbSet<FileInfo> FileInfo { get; set; }
|
||||
public DbSet<RulesetInfo> RulesetInfo { get; set; }
|
||||
|
||||
private readonly string connectionString;
|
||||
|
||||
private static readonly Lazy<OsuDbLoggerFactory> logger = new Lazy<OsuDbLoggerFactory>(() => new OsuDbLoggerFactory());
|
||||
@ -52,8 +54,6 @@ namespace osu.Game.Database
|
||||
{
|
||||
this.connectionString = connectionString;
|
||||
|
||||
Database.SetCommandTimeout(new TimeSpan(TimeSpan.TicksPerSecond * 10));
|
||||
|
||||
var connection = Database.GetDbConnection();
|
||||
connection.Open();
|
||||
using (var cmd = connection.CreateCommand())
|
||||
@ -70,7 +70,7 @@ namespace osu.Game.Database
|
||||
// this is required for the time being due to the way we are querying in places like BeatmapStore.
|
||||
// if we ever move to having consumers file their own .Includes, or get eager loading support, this could be re-enabled.
|
||||
.ConfigureWarnings(warnings => warnings.Ignore(CoreEventId.IncludeIgnoredWarning))
|
||||
.UseSqlite(connectionString)
|
||||
.UseSqlite(connectionString, sqliteOptions => sqliteOptions.CommandTimeout(10))
|
||||
.UseLoggerFactory(logger.Value);
|
||||
}
|
||||
|
||||
@ -95,6 +95,19 @@ namespace osu.Game.Database
|
||||
modelBuilder.Entity<BeatmapInfo>().HasOne(b => b.BaseDifficulty);
|
||||
}
|
||||
|
||||
public IDbContextTransaction BeginTransaction()
|
||||
{
|
||||
// return Database.BeginTransaction();
|
||||
return null;
|
||||
}
|
||||
|
||||
public new int SaveChanges(IDbContextTransaction transaction = null)
|
||||
{
|
||||
var ret = base.SaveChanges();
|
||||
transaction?.Commit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private class OsuDbLoggerFactory : ILoggerFactory
|
||||
{
|
||||
#region Disposal
|
||||
@ -153,7 +166,7 @@ namespace osu.Game.Database
|
||||
|
||||
public bool IsEnabled(LogLevel logLevel)
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG_DATABASE
|
||||
return logLevel > LogLevel.Debug;
|
||||
#else
|
||||
return logLevel > LogLevel.Information;
|
||||
|
@ -22,7 +22,7 @@ namespace osu.Game.IO
|
||||
|
||||
public Storage Storage => base.Storage;
|
||||
|
||||
public FileStore(Func<OsuDbContext> getContext, Storage storage) : base(getContext, storage.GetStorageForDirectory(@"files"))
|
||||
public FileStore(Func<OsuDbContext> createContext, Storage storage) : base(createContext, storage.GetStorageForDirectory(@"files"))
|
||||
{
|
||||
Store = new StorageBackedResourceStore(Storage);
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ namespace osu.Game.Input
|
||||
{
|
||||
public event Action KeyBindingChanged;
|
||||
|
||||
public KeyBindingStore(Func<OsuDbContext> getContext, RulesetStore rulesets, Storage storage = null)
|
||||
: base(getContext, storage)
|
||||
public KeyBindingStore(Func<OsuDbContext> createContext, RulesetStore rulesets, Storage storage = null)
|
||||
: base(createContext, storage)
|
||||
{
|
||||
foreach (var info in rulesets.AvailableRulesets)
|
||||
{
|
||||
@ -38,13 +38,14 @@ namespace osu.Game.Input
|
||||
|
||||
private void insertDefaults(IEnumerable<KeyBinding> defaults, int? rulesetId = null, int? variant = null)
|
||||
{
|
||||
using (var context = GetContext())
|
||||
using (var transaction = context.Database.BeginTransaction())
|
||||
var context = GetContext();
|
||||
|
||||
using (var transaction = context.BeginTransaction())
|
||||
{
|
||||
// compare counts in database vs defaults
|
||||
foreach (var group in defaults.GroupBy(k => k.Action))
|
||||
{
|
||||
int count = query(context, rulesetId, variant).Count(k => (int)k.Action == (int)group.Key);
|
||||
int count = Query(rulesetId, variant).Count(k => (int)k.Action == (int)group.Key);
|
||||
int aimCount = group.Count();
|
||||
|
||||
if (aimCount <= count)
|
||||
@ -61,8 +62,7 @@ namespace osu.Game.Input
|
||||
});
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
context.SaveChanges(transaction);
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,10 +72,8 @@ namespace osu.Game.Input
|
||||
/// <param name="rulesetId">The ruleset's internal ID.</param>
|
||||
/// <param name="variant">An optional variant.</param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<KeyBinding> Query(int? rulesetId = null, int? variant = null) => query(GetContext(), rulesetId, variant);
|
||||
|
||||
private IEnumerable<KeyBinding> query(OsuDbContext context, int? rulesetId = null, int? variant = null) =>
|
||||
context.DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant);
|
||||
public IEnumerable<KeyBinding> Query(int? rulesetId = null, int? variant = null) =>
|
||||
GetContext().DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant);
|
||||
|
||||
public void Update(KeyBinding keyBinding)
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ namespace osu.Game.Online.API
|
||||
return;
|
||||
|
||||
if (!WebRequest.Aborted) //could have been aborted by a Cancel() call
|
||||
WebRequest.BlockingPerform();
|
||||
WebRequest.Perform();
|
||||
|
||||
if (checkAndProcessFailure())
|
||||
return;
|
||||
|
@ -37,7 +37,7 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
try
|
||||
{
|
||||
req.BlockingPerform();
|
||||
req.Perform();
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -61,7 +61,7 @@ namespace osu.Game.Online.API
|
||||
ClientSecret = clientSecret
|
||||
})
|
||||
{
|
||||
req.BlockingPerform();
|
||||
req.Perform();
|
||||
|
||||
Token = req.ResponseObject;
|
||||
return true;
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
@ -51,7 +52,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
||||
restoreButton.Enabled.Value = false;
|
||||
Task.Run(() =>
|
||||
{
|
||||
foreach (var b in beatmaps.QueryBeatmaps(b => b.Hidden))
|
||||
foreach (var b in beatmaps.QueryBeatmaps(b => b.Hidden).ToList())
|
||||
beatmaps.Restore(b);
|
||||
}).ContinueWith(t => Schedule(() => restoreButton.Enabled.Value = true));
|
||||
}
|
||||
|
@ -13,11 +13,9 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
using (var host = new HeadlessGameHost($"test-{Guid.NewGuid()}", realtime: false))
|
||||
{
|
||||
host.Storage.DeleteDirectory(string.Empty);
|
||||
host.Run(new OsuTestCaseTestRunner(this));
|
||||
}
|
||||
|
||||
// clean up after each run
|
||||
//storage.DeleteDirectory(string.Empty);
|
||||
}
|
||||
|
||||
public class OsuTestCaseTestRunner : OsuGameBase
|
||||
|
Loading…
Reference in New Issue
Block a user