mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 06:36:31 +09:00
Stop using memory database. Load sample data local to TestCase.
Also makes the connection private.
This commit is contained in:
@ -17,7 +17,7 @@ namespace osu.Game.Database
|
||||
{
|
||||
public class BeatmapDatabase
|
||||
{
|
||||
public static SQLiteConnection Connection { get; set; }
|
||||
private static SQLiteConnection connection { get; set; }
|
||||
private BasicStorage storage;
|
||||
public event Action<BeatmapSetInfo> BeatmapSetAdded;
|
||||
|
||||
@ -29,25 +29,28 @@ namespace osu.Game.Database
|
||||
|
||||
ipc = new BeatmapImporter(host, this);
|
||||
|
||||
if (Connection == null)
|
||||
if (connection == null)
|
||||
{
|
||||
Connection = storage.GetDatabase(@"beatmaps");
|
||||
Connection.CreateTable<BeatmapMetadata>();
|
||||
Connection.CreateTable<BaseDifficulty>();
|
||||
Connection.CreateTable<BeatmapSetInfo>();
|
||||
Connection.CreateTable<BeatmapInfo>();
|
||||
connection = storage.GetDatabase(@"beatmaps");
|
||||
connection.CreateTable<BeatmapMetadata>();
|
||||
connection.CreateTable<BaseDifficulty>();
|
||||
connection.CreateTable<BeatmapSetInfo>();
|
||||
connection.CreateTable<BeatmapInfo>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
foreach (var setInfo in Query<BeatmapSetInfo>())
|
||||
storage.Delete(setInfo.Path);
|
||||
{
|
||||
if (storage.Exists(setInfo.Path))
|
||||
storage.Delete(setInfo.Path);
|
||||
}
|
||||
|
||||
Connection.DeleteAll<BeatmapMetadata>();
|
||||
Connection.DeleteAll<BaseDifficulty>();
|
||||
Connection.DeleteAll<BeatmapSetInfo>();
|
||||
Connection.DeleteAll<BeatmapInfo>();
|
||||
connection.DeleteAll<BeatmapMetadata>();
|
||||
connection.DeleteAll<BaseDifficulty>();
|
||||
connection.DeleteAll<BeatmapSetInfo>();
|
||||
connection.DeleteAll<BeatmapInfo>();
|
||||
}
|
||||
|
||||
public void Import(params string[] paths)
|
||||
@ -62,7 +65,7 @@ namespace osu.Game.Database
|
||||
using (var reader = ArchiveReader.GetReader(storage, path))
|
||||
metadata = reader.ReadMetadata();
|
||||
|
||||
if (Connection.Table<BeatmapSetInfo>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
||||
if (connection.Table<BeatmapSetInfo>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
||||
return; // TODO: Update this beatmap instead
|
||||
|
||||
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
|
||||
@ -104,11 +107,24 @@ namespace osu.Game.Database
|
||||
}
|
||||
}
|
||||
}
|
||||
Connection.InsertWithChildren(beatmapSet, true);
|
||||
BeatmapSetAdded?.Invoke(beatmapSet);
|
||||
|
||||
Import(new[] { beatmapSet });
|
||||
}
|
||||
}
|
||||
|
||||
public void Import(IEnumerable<BeatmapSetInfo> beatmapSets)
|
||||
{
|
||||
connection.BeginTransaction();
|
||||
|
||||
foreach (var s in beatmapSets)
|
||||
{
|
||||
connection.InsertWithChildren(s, true);
|
||||
BeatmapSetAdded?.Invoke(s);
|
||||
}
|
||||
|
||||
connection.Commit();
|
||||
}
|
||||
|
||||
public ArchiveReader GetReader(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
return ArchiveReader.GetReader(storage, beatmapSet.Path);
|
||||
@ -136,25 +152,25 @@ namespace osu.Game.Database
|
||||
|
||||
public TableQuery<T> Query<T>() where T : class
|
||||
{
|
||||
return Connection.Table<T>();
|
||||
return connection.Table<T>();
|
||||
}
|
||||
|
||||
public T GetWithChildren<T>(object id) where T : class
|
||||
{
|
||||
return Connection.GetWithChildren<T>(id);
|
||||
return connection.GetWithChildren<T>(id);
|
||||
}
|
||||
|
||||
public List<T> GetAllWithChildren<T>(Expression<Func<T, bool>> filter = null,
|
||||
bool recursive = true) where T : class
|
||||
{
|
||||
return Connection.GetAllWithChildren<T>(filter, recursive);
|
||||
return connection.GetAllWithChildren<T>(filter, recursive);
|
||||
}
|
||||
|
||||
public T GetChildren<T>(T item, bool recursive = true)
|
||||
{
|
||||
if (item == null) return default(T);
|
||||
|
||||
Connection.GetChildren(item, recursive);
|
||||
connection.GetChildren(item, recursive);
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -171,9 +187,9 @@ namespace osu.Game.Database
|
||||
if (!validTypes.Any(t => t == typeof(T)))
|
||||
throw new ArgumentException(nameof(T), "Must be a type managed by BeatmapDatabase");
|
||||
if (cascade)
|
||||
Connection.UpdateWithChildren(record);
|
||||
connection.UpdateWithChildren(record);
|
||||
else
|
||||
Connection.Update(record);
|
||||
connection.Update(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -16,6 +17,7 @@ using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Game.Beatmaps.Drawable;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
|
||||
namespace osu.Game.GameModes.Play
|
||||
{
|
||||
@ -122,7 +124,7 @@ namespace osu.Game.GameModes.Play
|
||||
}
|
||||
|
||||
beatmaps = (game as OsuGameBase).Beatmaps;
|
||||
beatmaps.BeatmapSetAdded += bset => Scheduler.Add(() => addBeatmapSet(bset));
|
||||
beatmaps.BeatmapSetAdded += s => Scheduler.Add(() => addBeatmapSet(s));
|
||||
Task.Factory.StartNew(addBeatmapSets);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user