1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-26 20:50:41 +08:00

Fix metadata cache version queries failing hard if the image is corrupted

This was not fatal but with this change it should recover in a slightly
better way.

Also incidentally fixes the cache refetch potentially being attempted
twice by each of the two background population tasks that use it.
This commit is contained in:
Bartłomiej Dach
2025-08-07 11:09:55 +02:00
Unverified
parent 7da94c4010
commit dac643121a
2 changed files with 19 additions and 11 deletions
@@ -238,12 +238,20 @@ namespace osu.Game.Beatmaps
});
}
public int GetCacheVersion()
public bool IsAtLeastVersion(int version)
{
using (var connection = getConnection())
try
{
connection.Open();
return getCacheVersion(connection);
using (var connection = getConnection())
{
connection.Open();
return getCacheVersion(connection) >= version;
}
}
catch (SqliteException ex) when (ex.SqliteErrorCode == 26 || ex.SqliteErrorCode == 11) // SQLITE_NOTADB, SQLITE_CORRUPT
{
// if the database is corrupted then return `false` as the consumer may want to just refetch the db themselves
return false;
}
}
@@ -72,12 +72,16 @@ namespace osu.Game.Database
[Resolved]
private OsuConfigManager config { get; set; } = null!;
private LocalCachedBeatmapMetadataSource localMetadataSource = null!;
protected virtual int TimeToSleepDuringGameplay => 30000;
protected override void LoadComplete()
{
base.LoadComplete();
localMetadataSource = new LocalCachedBeatmapMetadataSource(storage);
ProcessingTask = Task.Factory.StartNew(() =>
{
Logger.Log("Beginning background data store processing..");
@@ -532,8 +536,6 @@ namespace osu.Game.Database
private void backpopulateMissingSubmissionAndRankDates()
{
var localMetadataSource = new LocalCachedBeatmapMetadataSource(storage);
if (!localMetadataSource.Available)
{
Logger.Log("Cannot backpopulate missing submission/rank dates because the local metadata cache is missing.");
@@ -542,7 +544,7 @@ namespace osu.Game.Database
try
{
if (localMetadataSource.GetCacheVersion() < 2)
if (!localMetadataSource.IsAtLeastVersion(2))
{
Logger.Log("Cannot backpopulate missing submission/rank dates because the local metadata cache is too old.");
return;
@@ -630,14 +632,12 @@ namespace osu.Game.Database
private void backpopulateUserTags()
{
var localMetadataSource = new LocalCachedBeatmapMetadataSource(storage);
if (!localMetadataSource.Available || localMetadataSource.GetCacheVersion() < 3)
if (!localMetadataSource.Available || !localMetadataSource.IsAtLeastVersion(3))
{
Logger.Log(@"Local metadata cache has too low version to backpopulate user tags, attempting refetch...");
localMetadataSource.FetchCache().WaitSafely();
if (!localMetadataSource.Available || localMetadataSource.GetCacheVersion() < 3)
if (!localMetadataSource.Available || !localMetadataSource.IsAtLeastVersion(3))
{
Logger.Log(@"Local metadata cache refetch failed. Aborting user tags backpopulation.");
return;