Add new properties to BeatmapInfo to track online hash and updates

This commit is contained in:
Dean Herbert 2022-06-20 18:59:08 +09:00
parent 0bd4aee66c
commit 6ea380d649
4 changed files with 19 additions and 3 deletions

View File

@ -92,6 +92,16 @@ namespace osu.Game.Beatmaps
[Indexed]
public string MD5Hash { get; set; } = string.Empty;
public string OnlineMD5Hash { get; set; } = string.Empty;
public DateTimeOffset? LastOnlineUpdate { get; set; }
/// <summary>
/// Whether this beatmap matches the online version, based on fetched online metadata.
/// Will return <c>true</c> if no online metadata is available.
/// </summary>
public bool MatchesOnlineVersion => LastOnlineUpdate == null || MD5Hash == OnlineMD5Hash;
[JsonIgnore]
public bool Hidden { get; set; }

View File

@ -102,10 +102,13 @@ namespace osu.Game.Beatmaps
beatmapInfo.BeatmapSet.Status = res.BeatmapSet?.Status ?? BeatmapOnlineStatus.None;
beatmapInfo.BeatmapSet.OnlineID = res.OnlineBeatmapSetID;
beatmapInfo.OnlineMD5Hash = res.MD5Hash;
beatmapInfo.OnlineID = res.OnlineID;
beatmapInfo.Metadata.Author.OnlineID = res.AuthorID;
beatmapInfo.LastOnlineUpdate = DateTimeOffset.Now;
logForModel(set, $"Online retrieval mapped {beatmapInfo} to {res.OnlineBeatmapSetID} / {res.OnlineID}.");
}
}
@ -190,7 +193,7 @@ namespace osu.Game.Beatmaps
using (var cmd = db.CreateCommand())
{
cmd.CommandText = "SELECT beatmapset_id, beatmap_id, approved, user_id FROM osu_beatmaps WHERE checksum = @MD5Hash OR beatmap_id = @OnlineID OR filename = @Path";
cmd.CommandText = "SELECT beatmapset_id, beatmap_id, approved, user_id, checksum FROM osu_beatmaps WHERE checksum = @MD5Hash OR beatmap_id = @OnlineID OR filename = @Path";
cmd.Parameters.Add(new SqliteParameter("@MD5Hash", beatmapInfo.MD5Hash));
cmd.Parameters.Add(new SqliteParameter("@OnlineID", beatmapInfo.OnlineID));
@ -209,8 +212,8 @@ namespace osu.Game.Beatmaps
beatmapInfo.BeatmapSet.Status = status;
beatmapInfo.BeatmapSet.OnlineID = reader.GetInt32(0);
beatmapInfo.OnlineID = reader.GetInt32(1);
beatmapInfo.Metadata.Author.OnlineID = reader.GetInt32(3);
beatmapInfo.OnlineMD5Hash = reader.GetString(4);
logForModel(set, $"Cached local retrieval for {beatmapInfo}.");
return true;

View File

@ -56,6 +56,8 @@ namespace osu.Game.Beatmaps
// Before we use below, we want to invalidate.
workingBeatmapCache.Invalidate(beatmapSet);
// TODO: this call currently uses the local `online.db` lookup.
// We probably don't want this to happen after initial import (as the data may be stale).
onlineLookupQueue.Update(beatmapSet);
foreach (var beatmap in beatmapSet.Beatmaps)

View File

@ -61,8 +61,9 @@ namespace osu.Game.Database
/// 15 2022-07-13 Added LastPlayed to BeatmapInfo.
/// 16 2022-07-15 Removed HasReplay from ScoreInfo.
/// 17 2022-07-16 Added CountryCode to RealmUser.
/// 18 2022-07-19 Added OnlineMD5Hash and LastOnlineUpdate to BeatmapInfo.
/// </summary>
private const int schema_version = 17;
private const int schema_version = 18;
/// <summary>
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking realm retrieval during blocking periods.