1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-17 10:42:55 +08:00

Add support for retrieving user tags from local metadata cache

This commit is contained in:
Bartłomiej Dach
2025-07-23 09:12:18 +02:00
Unverified
parent a17d463c0f
commit 05923d3b2b
4 changed files with 72 additions and 1 deletions
@@ -63,7 +63,9 @@ namespace osu.Game.Beatmaps
DateRanked = res.BeatmapSet?.Ranked,
DateSubmitted = res.BeatmapSet?.Submitted,
MD5Hash = res.MD5Hash,
LastUpdated = res.LastUpdated
LastUpdated = res.LastUpdated,
// Tags are not populated because the response does not contain tag data.
// TODO: consider web change to include the tag data? or a second web request for the set to retrieve tags?
};
return true;
}
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Platform;
using osu.Game.Extensions;
using osu.Game.Online.API;
namespace osu.Game.Beatmaps
@@ -76,6 +77,7 @@ namespace osu.Game.Beatmaps
{
beatmapInfo.Status = res.BeatmapStatus;
beatmapInfo.Metadata.Author.OnlineID = res.AuthorID;
beatmapInfo.Metadata.UserTags.AddRange(res.UserTags);
}
}
@@ -105,7 +105,11 @@ namespace osu.Game.Beatmaps
switch (getCacheVersion(db))
{
case 2:
// can be removed 20260123
return queryCacheVersion2(db, beatmapInfo, out onlineMetadata);
case 3:
return queryCacheVersion3(db, beatmapInfo, out onlineMetadata);
}
}
@@ -311,6 +315,63 @@ namespace osu.Game.Beatmaps
return false;
}
private bool queryCacheVersion3(SqliteConnection db, BeatmapInfo beatmapInfo, out OnlineBeatmapMetadata? onlineMetadata)
{
Debug.Assert(beatmapInfo.BeatmapSet != null);
using (var cmd = db.CreateCommand())
{
cmd.CommandText =
"""
SELECT `b`.`beatmapset_id`, `b`.`beatmap_id`, `b`.`approved`, `b`.`user_id`, `b`.`checksum`, `b`.`last_update`, `s`.`submit_date`, `s`.`approved_date`
FROM `osu_beatmaps` AS `b`
JOIN `osu_beatmapsets` AS `s` ON `s`.`beatmapset_id` = `b`.`beatmapset_id`
WHERE (`b`.`checksum` = @MD5Hash OR `b`.`filename` = @Path)
""";
cmd.Parameters.Add(new SqliteParameter(@"@MD5Hash", beatmapInfo.MD5Hash));
cmd.Parameters.Add(new SqliteParameter(@"@Path", beatmapInfo.Path));
using (var reader = cmd.ExecuteReader())
{
if (!reader.Read())
{
onlineMetadata = null;
return false;
}
logForModel(beatmapInfo.BeatmapSet, $@"Cached local retrieval for {beatmapInfo} (cache version 3).");
onlineMetadata = new OnlineBeatmapMetadata
{
BeatmapSetID = reader.GetInt32(0),
BeatmapID = reader.GetInt32(1),
BeatmapStatus = (BeatmapOnlineStatus)reader.GetByte(2),
BeatmapSetStatus = (BeatmapOnlineStatus)reader.GetByte(2),
AuthorID = reader.GetInt32(3),
MD5Hash = reader.GetString(4),
LastUpdated = reader.GetDateTimeOffset(5),
DateSubmitted = reader.GetDateTimeOffset(6),
DateRanked = reader.GetDateTimeOffset(7),
};
}
}
using (var tagsCommand = db.CreateCommand())
{
tagsCommand.CommandText = "SELECT `name` FROM `tags` WHERE `id` IN (SELECT `tag_id` FROM `beatmap_tags` WHERE `beatmap_id` = @BeatmapID)";
tagsCommand.Parameters.Add(new SqliteParameter(@"@BeatmapID", onlineMetadata.BeatmapID));
using (var tagsReader = tagsCommand.ExecuteReader())
{
while (tagsReader.Read())
onlineMetadata.UserTags.Add(tagsReader.GetString(0));
}
}
return true;
}
private static void log(string message)
=> Logger.Log($@"[{nameof(LocalCachedBeatmapMetadataSource)}] {message}", LoggingTarget.Database);
@@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
namespace osu.Game.Beatmaps
{
@@ -57,5 +58,10 @@ namespace osu.Game.Beatmaps
/// The date when this metadata was last updated.
/// </summary>
public DateTimeOffset LastUpdated { get; init; }
/// <summary>
/// The list of tags that users have assigned to this beatmap.
/// </summary>
public List<string> UserTags { get; } = [];
}
}