Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve realm update performance #30893

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions osu.Game/Screens/Select/BeatmapCarousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using osu.Game.Screens.Select.Carousel;
using osuTK;
using osuTK.Input;
using Realms;

namespace osu.Game.Screens.Select
{
Expand Down Expand Up @@ -207,8 +206,6 @@ private void loadNewRoot()

private CarouselRoot root;

private IDisposable? subscriptionBeatmaps;

private readonly DrawablePool<DrawableCarouselBeatmapSet> setPool = new DrawablePool<DrawableCarouselBeatmapSet>(100);

private Sample? spinSample;
Expand Down Expand Up @@ -258,13 +255,6 @@ private void load(OsuConfigManager config, AudioManager audio, CancellationToken
}
}

protected override void LoadComplete()
{
base.LoadComplete();

subscriptionBeatmaps = realm.RegisterForNotifications(r => r.All<BeatmapInfo>().Where(b => !b.Hidden), beatmapsChanged);
}

private readonly HashSet<BeatmapSetInfo> setsRequiringUpdate = new HashSet<BeatmapSetInfo>();
private readonly HashSet<BeatmapSetInfo> setsRequiringRemoval = new HashSet<BeatmapSetInfo>();

Expand Down Expand Up @@ -366,35 +356,6 @@ private void processBeatmapChanges()
BeatmapSetInfo? fetchFromID(Guid id) => realm.Realm.Find<BeatmapSetInfo>(id);
}

private void beatmapsChanged(IRealmCollection<BeatmapInfo> sender, ChangeSet? changes)
{
// we only care about actual changes in hidden status.
if (changes == null)
return;

bool changed = false;

foreach (int i in changes.InsertedIndices)
{
var beatmapInfo = sender[i];
var beatmapSet = beatmapInfo.BeatmapSet;

Debug.Assert(beatmapSet != null);

// Only require to action here if the beatmap is missing.
// This avoids processing these events unnecessarily when new beatmaps are imported, for example.
if (root.BeatmapSetsByID.TryGetValue(beatmapSet.ID, out var existingSets)
&& existingSets.SelectMany(s => s.Beatmaps).All(b => b.BeatmapInfo.ID != beatmapInfo.ID))
{
updateBeatmapSet(beatmapSet.Detach());
changed = true;
}
}

if (changed)
invalidateAfterChange();
}

public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet) => Schedule(() =>
{
removeBeatmapSet(beatmapSet.ID);
Expand Down Expand Up @@ -1292,12 +1253,5 @@ protected override float FromScrollbarPosition(float scrollbarPosition)
return ScrollableExtent * ((scrollbarPosition - top_padding) / (ScrollbarMovementExtent - (top_padding + bottom_padding)));
}
}

protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);

subscriptionBeatmaps?.Dispose();
}
}
}
Loading