mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Add a lower level ConsumableItems implementation
This commit is contained in:
@ -86,7 +86,7 @@ namespace osu.Game.Beatmaps
|
|||||||
protected override BeatmapSetInfo CheckForExisting(BeatmapSetInfo model)
|
protected override BeatmapSetInfo CheckForExisting(BeatmapSetInfo model)
|
||||||
{
|
{
|
||||||
// check if this beatmap has already been imported and exit early if so
|
// check if this beatmap has already been imported and exit early if so
|
||||||
var existingHashMatch = beatmaps.BeatmapSets.FirstOrDefault(b => b.Hash == model.Hash);
|
var existingHashMatch = beatmaps.ConsumableItems.FirstOrDefault(b => b.Hash == model.Hash);
|
||||||
if (existingHashMatch != null)
|
if (existingHashMatch != null)
|
||||||
{
|
{
|
||||||
Undelete(existingHashMatch);
|
Undelete(existingHashMatch);
|
||||||
@ -96,7 +96,7 @@ namespace osu.Game.Beatmaps
|
|||||||
// check if a set already exists with the same online id
|
// check if a set already exists with the same online id
|
||||||
if (model.OnlineBeatmapSetID != null)
|
if (model.OnlineBeatmapSetID != null)
|
||||||
{
|
{
|
||||||
var existingOnlineId = beatmaps.BeatmapSets.FirstOrDefault(b => b.OnlineBeatmapSetID == model.OnlineBeatmapSetID);
|
var existingOnlineId = beatmaps.ConsumableItems.FirstOrDefault(b => b.OnlineBeatmapSetID == model.OnlineBeatmapSetID);
|
||||||
if (existingOnlineId != null)
|
if (existingOnlineId != null)
|
||||||
{
|
{
|
||||||
Delete(existingOnlineId);
|
Delete(existingOnlineId);
|
||||||
@ -229,20 +229,20 @@ namespace osu.Game.Beatmaps
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query">The query.</param>
|
/// <param name="query">The query.</param>
|
||||||
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
||||||
public BeatmapSetInfo QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.BeatmapSets.AsNoTracking().FirstOrDefault(query);
|
public BeatmapSetInfo QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.ConsumableItems.AsNoTracking().FirstOrDefault(query);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
|
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
||||||
public List<BeatmapSetInfo> GetAllUsableBeatmapSets() => beatmaps.BeatmapSets.Where(s => !s.DeletePending && !s.Protected).ToList();
|
public List<BeatmapSetInfo> GetAllUsableBeatmapSets() => beatmaps.ConsumableItems.Where(s => !s.DeletePending && !s.Protected).ToList();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query">The query.</param>
|
/// <param name="query">The query.</param>
|
||||||
/// <returns>Results from the provided query.</returns>
|
/// <returns>Results from the provided query.</returns>
|
||||||
public IEnumerable<BeatmapSetInfo> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.BeatmapSets.AsNoTracking().Where(query);
|
public IEnumerable<BeatmapSetInfo> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.ConsumableItems.AsNoTracking().Where(query);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
|
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
|
||||||
|
@ -63,13 +63,19 @@ namespace osu.Game.Beatmaps
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IQueryable<BeatmapSetInfo> AddIncludesForDeletion(IQueryable<BeatmapSetInfo> query)
|
protected override IQueryable<BeatmapSetInfo> AddIncludesForDeletion(IQueryable<BeatmapSetInfo> query) =>
|
||||||
{
|
base.AddIncludesForDeletion(query)
|
||||||
return base.AddIncludesForDeletion(query)
|
|
||||||
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
||||||
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
||||||
.Include(s => s.Metadata);
|
.Include(s => s.Metadata);
|
||||||
}
|
|
||||||
|
protected override IQueryable<BeatmapSetInfo> AddIncludesForConsumption(IQueryable<BeatmapSetInfo> query) =>
|
||||||
|
base.AddIncludesForConsumption(query)
|
||||||
|
.Include(s => s.Metadata)
|
||||||
|
.Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset)
|
||||||
|
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
||||||
|
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
||||||
|
.Include(s => s.Files).ThenInclude(f => f.FileInfo);
|
||||||
|
|
||||||
protected override void Purge(List<BeatmapSetInfo> items, OsuDbContext context)
|
protected override void Purge(List<BeatmapSetInfo> items, OsuDbContext context)
|
||||||
{
|
{
|
||||||
@ -83,14 +89,8 @@ namespace osu.Game.Beatmaps
|
|||||||
base.Purge(items, context);
|
base.Purge(items, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<BeatmapSetInfo> BeatmapSets => ContextFactory.Get().BeatmapSetInfo
|
public IQueryable<BeatmapInfo> Beatmaps =>
|
||||||
.Include(s => s.Metadata)
|
ContextFactory.Get().BeatmapInfo
|
||||||
.Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset)
|
|
||||||
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
|
||||||
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
|
||||||
.Include(s => s.Files).ThenInclude(f => f.FileInfo);
|
|
||||||
|
|
||||||
public IQueryable<BeatmapInfo> Beatmaps => ContextFactory.Get().BeatmapInfo
|
|
||||||
.Include(b => b.BeatmapSet).ThenInclude(s => s.Metadata)
|
.Include(b => b.BeatmapSet).ThenInclude(s => s.Metadata)
|
||||||
.Include(b => b.BeatmapSet).ThenInclude(s => s.Files).ThenInclude(f => f.FileInfo)
|
.Include(b => b.BeatmapSet).ThenInclude(s => s.Files).ThenInclude(f => f.FileInfo)
|
||||||
.Include(b => b.Metadata)
|
.Include(b => b.Metadata)
|
||||||
|
@ -21,6 +21,11 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Access items pre-populated with includes for consumption.
|
||||||
|
/// </summary>
|
||||||
|
public IQueryable<T> ConsumableItems => AddIncludesForConsumption(ContextFactory.Get().Set<T>());
|
||||||
|
|
||||||
public void Add(T item)
|
public void Add(T item)
|
||||||
{
|
{
|
||||||
using (var usage = ContextFactory.GetForWrite())
|
using (var usage = ContextFactory.GetForWrite())
|
||||||
|
Reference in New Issue
Block a user