1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 02:02:53 +08:00

Hand off comparison logic for database query to implementors

Equals overrides are not used in EF queries without running the comaprison locally instead of on the database, so to preserve that the comparison logic is instead implemented on a per manager basis.
This commit is contained in:
naoey 2019-06-27 15:14:57 +05:30
parent 72bb6f8c12
commit 61260cf599
No known key found for this signature in database
GPG Key ID: 670DA9BE3DF7EE60
2 changed files with 11 additions and 1 deletions

View File

@ -145,6 +145,8 @@ namespace osu.Game.Beatmaps
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineBeatmapID = null);
}
protected override bool CheckLocalAvailability(BeatmapSetInfo model, IQueryable<BeatmapSetInfo> items) => items.Any(b => b.OnlineBeatmapSetID == model.OnlineBeatmapSetID);
/// <summary>
/// Delete a beatmap difficulty.
/// </summary>

View File

@ -110,7 +110,15 @@ namespace osu.Game.Database
return true;
}
public virtual bool IsAvailableLocally(TModel model) => modelStore.ConsumableItems.Any(m => m.Equals(model) && !m.DeletePending);
public bool IsAvailableLocally(TModel model) => CheckLocalAvailability(model, modelStore.ConsumableItems.Where(m => !m.DeletePending));
/// <summary>
/// Performs implementation specific comparisons to determine whether a given model is present in the local store.
/// </summary>
/// <param name="model">The <see cref="TModel"/> whose existence needs to be checked.</param>
/// <param name="items">The usable items present in the store.</param>
/// <returns>Whether the <see cref="TModel"/> exists.</returns>
protected abstract bool CheckLocalAvailability(TModel model, IQueryable<TModel> items);
public ArchiveDownloadRequest<TModel> GetExistingDownload(TModel model) => currentDownloads.Find(r => r.Model.Equals(model));