mirror of
https://github.com/ppy/osu.git
synced 2025-03-04 02:03:00 +08:00
Merge pull request #31509 from bdach/local-metadata-cache-corruption
Refetch local metadata cache if corruption is detected
This commit is contained in:
commit
bf23c67603
@ -113,6 +113,31 @@ namespace osu.Game.Beatmaps
|
|||||||
return queryCacheVersion2(db, beatmapInfo, out onlineMetadata);
|
return queryCacheVersion2(db, beatmapInfo, out onlineMetadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onlineMetadata = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (SqliteException sqliteException)
|
||||||
|
{
|
||||||
|
onlineMetadata = null;
|
||||||
|
|
||||||
|
// There have been cases where the user's local database is corrupt.
|
||||||
|
// Let's attempt to identify these cases and re-initialise the local cache.
|
||||||
|
switch (sqliteException.SqliteErrorCode)
|
||||||
|
{
|
||||||
|
case 26: // SQLITE_NOTADB
|
||||||
|
case 11: // SQLITE_CORRUPT
|
||||||
|
// only attempt purge & re-download if there is no other refetch in progress
|
||||||
|
if (cacheDownloadRequest != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
tryPurgeCache();
|
||||||
|
prepareLocalCache();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
logForModel(beatmapInfo.BeatmapSet, $@"Cached local retrieval for {beatmapInfo} failed with unhandled sqlite error {sqliteException}.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -120,9 +145,22 @@ namespace osu.Game.Beatmaps
|
|||||||
onlineMetadata = null;
|
onlineMetadata = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onlineMetadata = null;
|
private void tryPurgeCache()
|
||||||
return false;
|
{
|
||||||
|
log(@"Local metadata cache is corrupted; attempting purge.");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(storage.GetFullPath(cache_database_name));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
log($@"Failed to purge local metadata cache: {ex}");
|
||||||
|
}
|
||||||
|
|
||||||
|
log(@"Local metadata cache purged due to corruption.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqliteConnection getConnection() =>
|
private SqliteConnection getConnection() =>
|
||||||
|
@ -11,7 +11,6 @@ using System.Linq.Expressions;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Development;
|
using osu.Framework.Development;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
@ -414,18 +413,7 @@ namespace osu.Game.Database
|
|||||||
/// Compact this realm.
|
/// Compact this realm.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Compact()
|
public bool Compact() => Realm.Compact(getConfiguration());
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return Realm.Compact(getConfiguration());
|
|
||||||
}
|
|
||||||
// Catch can be removed along with entity framework. Is specifically to allow a failure message to arrive to the user (see similar catches in EFToRealmMigrator).
|
|
||||||
catch (AggregateException ae) when (RuntimeInfo.OS == RuntimeInfo.Platform.macOS && ae.Flatten().InnerException is TypeInitializationException)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run work on realm with a return value.
|
/// Run work on realm with a return value.
|
||||||
@ -721,11 +709,6 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
return Realm.GetInstance(getConfiguration());
|
return Realm.GetInstance(getConfiguration());
|
||||||
}
|
}
|
||||||
// Catch can be removed along with entity framework. Is specifically to allow a failure message to arrive to the user (see similar catches in EFToRealmMigrator).
|
|
||||||
catch (AggregateException ae) when (RuntimeInfo.OS == RuntimeInfo.Platform.macOS && ae.Flatten().InnerException is TypeInitializationException)
|
|
||||||
{
|
|
||||||
return Realm.GetInstance();
|
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (tookSemaphoreLock)
|
if (tookSemaphoreLock)
|
||||||
|
Loading…
Reference in New Issue
Block a user