mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 22:22:54 +08:00
Fix edge cases in online availability tracker and combine query code
This commit is contained in:
parent
ca7e11057c
commit
a7958b1d31
@ -12,6 +12,7 @@ using osu.Framework.Logging;
|
|||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
|
using Realms;
|
||||||
|
|
||||||
namespace osu.Game.Online.Rooms
|
namespace osu.Game.Online.Rooms
|
||||||
{
|
{
|
||||||
@ -28,9 +29,6 @@ namespace osu.Game.Online.Rooms
|
|||||||
// Required to allow child components to update. Can potentially be replaced with a `CompositeComponent` class if or when we make one.
|
// Required to allow child components to update. Can potentially be replaced with a `CompositeComponent` class if or when we make one.
|
||||||
protected override bool RequiresChildrenUpdate => true;
|
protected override bool RequiresChildrenUpdate => true;
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private BeatmapManager beatmapManager { get; set; }
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private RealmContextFactory realmContextFactory { get; set; } = null!;
|
private RealmContextFactory realmContextFactory { get; set; } = null!;
|
||||||
|
|
||||||
@ -45,11 +43,6 @@ namespace osu.Game.Online.Rooms
|
|||||||
|
|
||||||
private BeatmapDownloadTracker downloadTracker;
|
private BeatmapDownloadTracker downloadTracker;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The beatmap matching the required hash (and providing a final <see cref="BeatmapAvailability.LocallyAvailable"/> state).
|
|
||||||
/// </summary>
|
|
||||||
private BeatmapInfo matchingHash;
|
|
||||||
|
|
||||||
private IDisposable realmSubscription;
|
private IDisposable realmSubscription;
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -83,17 +76,15 @@ namespace osu.Game.Online.Rooms
|
|||||||
progressUpdate = Scheduler.AddDelayed(updateAvailability, progressUpdate == null ? 0 : 500);
|
progressUpdate = Scheduler.AddDelayed(updateAvailability, progressUpdate == null ? 0 : 500);
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
// handles changes to hash that didn't occur from the import process (ie. a user editing the beatmap in the editor, somehow).
|
||||||
realmSubscription?.Dispose();
|
realmSubscription?.Dispose();
|
||||||
realmSubscription = realmContextFactory.Context
|
realmSubscription = filteredBeatmaps().QueryAsyncWithNotifications((items, changes, ___) =>
|
||||||
.All<BeatmapInfo>()
|
{
|
||||||
.Where(b => b.OnlineID == item.NewValue.BeatmapID && b.MD5Hash == item.NewValue.Beatmap.Value.MD5Hash)
|
if (changes == null)
|
||||||
.QueryAsyncWithNotifications((items, changes, ___) =>
|
return;
|
||||||
{
|
|
||||||
if (changes == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Scheduler.AddOnce(updateAvailability);
|
Scheduler.AddOnce(updateAvailability);
|
||||||
});
|
});
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,9 +93,6 @@ namespace osu.Game.Online.Rooms
|
|||||||
if (downloadTracker == null)
|
if (downloadTracker == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// will be repopulated below if still valid.
|
|
||||||
matchingHash = null;
|
|
||||||
|
|
||||||
switch (downloadTracker.State.Value)
|
switch (downloadTracker.State.Value)
|
||||||
{
|
{
|
||||||
case DownloadState.NotDownloaded:
|
case DownloadState.NotDownloaded:
|
||||||
@ -120,9 +108,7 @@ namespace osu.Game.Online.Rooms
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DownloadState.LocallyAvailable:
|
case DownloadState.LocallyAvailable:
|
||||||
matchingHash = findMatchingHash();
|
bool hashMatches = filteredBeatmaps().Any();
|
||||||
|
|
||||||
bool hashMatches = matchingHash != null;
|
|
||||||
|
|
||||||
availability.Value = hashMatches ? BeatmapAvailability.LocallyAvailable() : BeatmapAvailability.NotDownloaded();
|
availability.Value = hashMatches ? BeatmapAvailability.LocallyAvailable() : BeatmapAvailability.NotDownloaded();
|
||||||
|
|
||||||
@ -137,18 +123,14 @@ namespace osu.Game.Online.Rooms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BeatmapInfo findMatchingHash()
|
private IQueryable<BeatmapInfo> filteredBeatmaps()
|
||||||
{
|
{
|
||||||
int onlineId = SelectedItem.Value.Beatmap.Value.OnlineID;
|
int onlineId = SelectedItem.Value.Beatmap.Value.OnlineID;
|
||||||
string checksum = SelectedItem.Value.Beatmap.Value.MD5Hash;
|
string checksum = SelectedItem.Value.Beatmap.Value.MD5Hash;
|
||||||
|
|
||||||
var foundBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineID == onlineId && b.MD5Hash == checksum);
|
return realmContextFactory.Context
|
||||||
|
.All<BeatmapInfo>()
|
||||||
// can't be included in the above query due to realm limitations.
|
.Filter("OnlineID == $0 && MD5Hash == $1 && BeatmapSet.DeletePending == false", onlineId, checksum);
|
||||||
if (foundBeatmap?.BeatmapSet?.DeletePending == true)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return foundBeatmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
Loading…
Reference in New Issue
Block a user