mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 16:43:52 +09:00
Merge branch 'master' into carousel-performance-n
This commit is contained in:
@ -26,8 +26,6 @@ namespace osu.Game.Database
|
|||||||
private readonly OsuConfigManager config;
|
private readonly OsuConfigManager config;
|
||||||
private readonly Storage storage;
|
private readonly Storage storage;
|
||||||
|
|
||||||
private bool hasTakenBackup;
|
|
||||||
|
|
||||||
public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config, Storage storage)
|
public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config, Storage storage)
|
||||||
{
|
{
|
||||||
this.efContextFactory = efContextFactory;
|
this.efContextFactory = efContextFactory;
|
||||||
@ -38,6 +36,8 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
|
createBackup();
|
||||||
|
|
||||||
using (var ef = efContextFactory.Get())
|
using (var ef = efContextFactory.Get())
|
||||||
{
|
{
|
||||||
migrateSettings(ef);
|
migrateSettings(ef);
|
||||||
@ -77,8 +77,6 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
Logger.Log($"Found {count} beatmaps in EF", LoggingTarget.Database);
|
Logger.Log($"Found {count} beatmaps in EF", LoggingTarget.Database);
|
||||||
|
|
||||||
ensureBackup();
|
|
||||||
|
|
||||||
// only migrate data if the realm database is empty.
|
// only migrate data if the realm database is empty.
|
||||||
// note that this cannot be written as: `realm.All<BeatmapSetInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
// note that this cannot be written as: `realm.All<BeatmapSetInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
||||||
if (realm.All<BeatmapSetInfo>().Any(s => !s.Protected))
|
if (realm.All<BeatmapSetInfo>().Any(s => !s.Protected))
|
||||||
@ -210,8 +208,6 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
Logger.Log($"Found {count} scores in EF", LoggingTarget.Database);
|
Logger.Log($"Found {count} scores in EF", LoggingTarget.Database);
|
||||||
|
|
||||||
ensureBackup();
|
|
||||||
|
|
||||||
// only migrate data if the realm database is empty.
|
// only migrate data if the realm database is empty.
|
||||||
if (realm.All<ScoreInfo>().Any())
|
if (realm.All<ScoreInfo>().Any())
|
||||||
{
|
{
|
||||||
@ -291,8 +287,6 @@ namespace osu.Game.Database
|
|||||||
if (!existingSkins.Any())
|
if (!existingSkins.Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ensureBackup();
|
|
||||||
|
|
||||||
var userSkinChoice = config.GetBindable<string>(OsuSetting.Skin);
|
var userSkinChoice = config.GetBindable<string>(OsuSetting.Skin);
|
||||||
int.TryParse(userSkinChoice.Value, out int userSkinInt);
|
int.TryParse(userSkinChoice.Value, out int userSkinInt);
|
||||||
|
|
||||||
@ -363,7 +357,6 @@ namespace osu.Game.Database
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Logger.Log("Beginning settings migration to realm", LoggingTarget.Database);
|
Logger.Log("Beginning settings migration to realm", LoggingTarget.Database);
|
||||||
ensureBackup();
|
|
||||||
|
|
||||||
using (var realm = realmContextFactory.CreateContext())
|
using (var realm = realmContextFactory.CreateContext())
|
||||||
using (var transaction = realm.BeginWrite())
|
using (var transaction = realm.BeginWrite())
|
||||||
@ -400,9 +393,7 @@ namespace osu.Game.Database
|
|||||||
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
||||||
efContextFactory.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
|
efContextFactory.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
|
||||||
|
|
||||||
private void ensureBackup()
|
private void createBackup()
|
||||||
{
|
|
||||||
if (!hasTakenBackup)
|
|
||||||
{
|
{
|
||||||
string migration = $"before_final_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
string migration = $"before_final_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||||
|
|
||||||
@ -412,9 +403,6 @@ namespace osu.Game.Database
|
|||||||
using (var source = storage.GetStream("collection.db"))
|
using (var source = storage.GetStream("collection.db"))
|
||||||
using (var destination = storage.GetStream($"collection.{migration}.db", FileAccess.Write, FileMode.CreateNew))
|
using (var destination = storage.GetStream($"collection.{migration}.db", FileAccess.Write, FileMode.CreateNew))
|
||||||
source.CopyTo(destination);
|
source.CopyTo(destination);
|
||||||
|
|
||||||
hasTakenBackup = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -367,9 +367,24 @@ namespace osu.Game.Database
|
|||||||
using (BlockAllOperations())
|
using (BlockAllOperations())
|
||||||
{
|
{
|
||||||
Logger.Log($"Creating full realm database backup at {backupFilename}", LoggingTarget.Database);
|
Logger.Log($"Creating full realm database backup at {backupFilename}", LoggingTarget.Database);
|
||||||
|
|
||||||
|
int attempts = 10;
|
||||||
|
|
||||||
|
while (attempts-- > 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
using (var source = storage.GetStream(Filename))
|
using (var source = storage.GetStream(Filename))
|
||||||
using (var destination = storage.GetStream(backupFilename, FileAccess.Write, FileMode.CreateNew))
|
using (var destination = storage.GetStream(backupFilename, FileAccess.Write, FileMode.CreateNew))
|
||||||
source.CopyTo(destination);
|
source.CopyTo(destination);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (IOException)
|
||||||
|
{
|
||||||
|
// file may be locked during use.
|
||||||
|
Thread.Sleep(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,17 +305,20 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
root.AddChild(newSet);
|
root.AddChild(newSet);
|
||||||
|
|
||||||
// only reset scroll position if already near the scroll target.
|
|
||||||
// without this, during a large beatmap import it is impossible to navigate the carousel.
|
|
||||||
applyActiveCriteria(false, alwaysResetScrollPosition: false);
|
|
||||||
|
|
||||||
// check if we can/need to maintain our current selection.
|
// check if we can/need to maintain our current selection.
|
||||||
if (previouslySelectedID != null)
|
if (previouslySelectedID != null)
|
||||||
select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.BeatmapInfo.ID == previouslySelectedID) ?? newSet);
|
select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.BeatmapInfo.ID == previouslySelectedID) ?? newSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
itemsCache.Invalidate();
|
itemsCache.Invalidate();
|
||||||
Schedule(() => BeatmapSetsChanged?.Invoke());
|
|
||||||
|
Schedule(() =>
|
||||||
|
{
|
||||||
|
if (!Scroll.UserScrolling)
|
||||||
|
ScrollToSelected(true);
|
||||||
|
|
||||||
|
BeatmapSetsChanged?.Invoke();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -55,7 +55,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(BeatmapInfo.StarRating);
|
match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(BeatmapInfo.StarRating);
|
||||||
|
|
||||||
if (match)
|
if (match && criteria.SearchTerms.Length > 0)
|
||||||
{
|
{
|
||||||
string[] terms = BeatmapInfo.GetSearchableTerms();
|
string[] terms = BeatmapInfo.GetSearchableTerms();
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select.Carousel
|
namespace osu.Game.Screens.Select.Carousel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -11,7 +13,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class CarouselGroup : CarouselItem
|
public class CarouselGroup : CarouselItem
|
||||||
{
|
{
|
||||||
public override DrawableCarouselItem CreateDrawableRepresentation() => null;
|
public override DrawableCarouselItem? CreateDrawableRepresentation() => null;
|
||||||
|
|
||||||
public IReadOnlyList<CarouselItem> Children => InternalChildren;
|
public IReadOnlyList<CarouselItem> Children => InternalChildren;
|
||||||
|
|
||||||
@ -23,6 +25,10 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private ulong currentChildID;
|
private ulong currentChildID;
|
||||||
|
|
||||||
|
private Comparer<CarouselItem>? criteriaComparer;
|
||||||
|
|
||||||
|
private FilterCriteria? lastCriteria;
|
||||||
|
|
||||||
public virtual void RemoveChild(CarouselItem i)
|
public virtual void RemoveChild(CarouselItem i)
|
||||||
{
|
{
|
||||||
InternalChildren.Remove(i);
|
InternalChildren.Remove(i);
|
||||||
@ -36,10 +42,24 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
{
|
{
|
||||||
i.State.ValueChanged += state => ChildItemStateChanged(i, state.NewValue);
|
i.State.ValueChanged += state => ChildItemStateChanged(i, state.NewValue);
|
||||||
i.ChildID = ++currentChildID;
|
i.ChildID = ++currentChildID;
|
||||||
|
|
||||||
|
if (lastCriteria != null)
|
||||||
|
{
|
||||||
|
i.Filter(lastCriteria);
|
||||||
|
|
||||||
|
int index = InternalChildren.BinarySearch(i, criteriaComparer);
|
||||||
|
if (index < 0) index = ~index; // BinarySearch hacks multiple return values with 2's complement.
|
||||||
|
|
||||||
|
InternalChildren.Insert(index, i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// criteria may be null for initial population. the filtering will be applied post-add.
|
||||||
InternalChildren.Add(i);
|
InternalChildren.Add(i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public CarouselGroup(List<CarouselItem> items = null)
|
public CarouselGroup(List<CarouselItem>? items = null)
|
||||||
{
|
{
|
||||||
if (items != null) InternalChildren = items;
|
if (items != null) InternalChildren = items;
|
||||||
|
|
||||||
@ -67,9 +87,12 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
base.Filter(criteria);
|
base.Filter(criteria);
|
||||||
|
|
||||||
InternalChildren.ForEach(c => c.Filter(criteria));
|
InternalChildren.ForEach(c => c.Filter(criteria));
|
||||||
|
|
||||||
// IEnumerable<T>.OrderBy() is used instead of List<T>.Sort() to ensure sorting stability
|
// IEnumerable<T>.OrderBy() is used instead of List<T>.Sort() to ensure sorting stability
|
||||||
var criteriaComparer = Comparer<CarouselItem>.Create((x, y) => x.CompareTo(criteria, y));
|
criteriaComparer = Comparer<CarouselItem>.Create((x, y) => x.CompareTo(criteria, y));
|
||||||
InternalChildren = InternalChildren.OrderBy(c => c, criteriaComparer).ToList();
|
InternalChildren = InternalChildren.OrderBy(c => c, criteriaComparer).ToList();
|
||||||
|
|
||||||
|
lastCriteria = criteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
|
protected virtual void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
|
||||||
|
Reference in New Issue
Block a user