1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

Merge pull request #15682 from peppy/primary-key-consistency

Add `IsManaged` helper method to EF classes to match realm implementation
This commit is contained in:
Bartłomiej Dach 2021-12-08 19:17:39 +01:00 committed by GitHub
commit 69fc7782ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 32 additions and 8 deletions

View File

@ -49,7 +49,7 @@ namespace osu.Game.Tests.Visual.Editing
public void TestCreateNewBeatmap()
{
AddStep("save beatmap", () => Editor.Save());
AddAssert("new beatmap persisted", () => EditorBeatmap.BeatmapInfo.ID > 0);
AddAssert("new beatmap persisted", () => EditorBeatmap.BeatmapInfo.IsManaged);
AddAssert("new beatmap in database", () => beatmapManager.QueryBeatmapSet(s => s.ID == EditorBeatmap.BeatmapInfo.BeatmapSet.ID)?.DeletePending == false);
}

View File

@ -15,6 +15,8 @@ namespace osu.Game.Beatmaps
public int ID { get; set; }
public bool IsManaged => ID > 0;
public float DrainRate { get; set; } = DEFAULT_DIFFICULTY;
public float CircleSize { get; set; } = DEFAULT_DIFFICULTY;
public float OverallDifficulty { get; set; } = DEFAULT_DIFFICULTY;

View File

@ -135,7 +135,7 @@ namespace osu.Game.Beatmaps
var localRulesetInfo = rulesetInfo as RulesetInfo;
// Difficulty can only be computed if the beatmap and ruleset are locally available.
if (localBeatmapInfo == null || localBeatmapInfo.ID == 0 || localRulesetInfo == null)
if (localBeatmapInfo?.IsManaged != true || localRulesetInfo == null)
{
// If not, fall back to the existing star difficulty (e.g. from an online source).
return Task.FromResult<StarDifficulty?>(new StarDifficulty(beatmapInfo.StarRating, (beatmapInfo as IBeatmapOnlineInfo)?.MaxCombo ?? 0));

View File

@ -20,6 +20,8 @@ namespace osu.Game.Beatmaps
{
public int ID { get; set; }
public bool IsManaged => ID > 0;
public int BeatmapVersion;
private int? onlineID;

View File

@ -20,6 +20,8 @@ namespace osu.Game.Beatmaps
{
public int ID { get; set; }
public bool IsManaged => ID > 0;
public string Title { get; set; } = string.Empty;
[JsonProperty("title_unicode")]

View File

@ -11,6 +11,8 @@ namespace osu.Game.Beatmaps
{
public int ID { get; set; }
public bool IsManaged => ID > 0;
public int BeatmapSetInfoID { get; set; }
public int FileInfoID { get; set; }

View File

@ -18,6 +18,8 @@ namespace osu.Game.Beatmaps
{
public int ID { get; set; }
public bool IsManaged => ID > 0;
private int? onlineID;
[Column("OnlineBeatmapSetID")]

View File

@ -11,6 +11,8 @@ namespace osu.Game.Configuration
{
public int ID { get; set; }
public bool IsManaged => ID > 0;
public int? RulesetID { get; set; }
public int? Variant { get; set; }

View File

@ -476,7 +476,7 @@ namespace osu.Game.Database
{
Files.Dereference(file.FileInfo);
if (file.ID > 0)
if (file.IsManaged)
{
// This shouldn't be required, but here for safety in case the provided TModel is not being change tracked
// Definitely can be removed once we rework the database backend.
@ -505,7 +505,7 @@ namespace osu.Game.Database
});
}
if (model.ID > 0)
if (model.IsManaged)
Update(model);
}
@ -737,7 +737,7 @@ namespace osu.Game.Database
/// <param name="items">The usable items present in the store.</param>
/// <returns>Whether the <typeparamref name="TModel"/> exists.</returns>
protected virtual bool CheckLocalAvailability(TModel model, IQueryable<TModel> items)
=> model.ID > 0 && items.Any(i => i.ID == model.ID && i.Files.Any());
=> model.IsManaged && items.Any(i => i.ID == model.ID && i.Files.Any());
/// <summary>
/// Whether import can be skipped after finding an existing import early in the process.

View File

@ -11,5 +11,7 @@ namespace osu.Game.Database
[JsonIgnore]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
int ID { get; set; }
bool IsManaged { get; }
}
}

View File

@ -9,6 +9,8 @@ namespace osu.Game.IO
{
public int ID { get; set; }
public bool IsManaged => ID > 0;
public string Hash { get; set; }
public int ReferenceCount { get; set; }

View File

@ -11,6 +11,8 @@ namespace osu.Game.Scoring
{
public int ID { get; set; }
public bool IsManaged => ID > 0;
public int FileInfoID { get; set; }
public FileInfo FileInfo { get; set; }

View File

@ -22,6 +22,8 @@ namespace osu.Game.Scoring
{
public int ID { get; set; }
public bool IsManaged => ID > 0;
public ScoreRank Rank { get; set; }
public long TotalScore { get; set; }

View File

@ -807,14 +807,14 @@ namespace osu.Game.Screens.Select
private void delete(BeatmapSetInfo beatmap)
{
if (beatmap == null || beatmap.ID <= 0) return;
if (beatmap == null || !beatmap.IsManaged) return;
dialogOverlay?.Push(new BeatmapDeleteDialog(beatmap));
}
private void clearScores(BeatmapInfo beatmapInfo)
{
if (beatmapInfo == null || beatmapInfo.ID <= 0) return;
if (beatmapInfo == null || !beatmapInfo.IsManaged) return;
dialogOverlay?.Push(new BeatmapClearScoresDialog(beatmapInfo, () =>
// schedule done here rather than inside the dialog as the dialog may fade out and never callback.

View File

@ -57,5 +57,7 @@ namespace osu.Game.Skinning
string author = Creator == null ? string.Empty : $"({Creator})";
return $"{Name} {author}".Trim();
}
public bool IsManaged => ID > 0;
}
}

View File

@ -11,6 +11,8 @@ namespace osu.Game.Skinning
{
public int ID { get; set; }
public bool IsManaged => ID > 0;
public int SkinInfoID { get; set; }
public EFSkinInfo SkinInfo { get; set; }

View File

@ -1,4 +1,4 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;