mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:03:22 +08:00
Merge branch 'master' into realm-integration/stable-import-flow
This commit is contained in:
commit
6d60725b31
@ -1050,7 +1050,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
|
||||
private static void checkSingleReferencedFileCount(OsuGameBase osu, int expected)
|
||||
{
|
||||
Assert.AreEqual(expected, osu.Dependencies.Get<FileStore>().QueryFiles(f => f.ReferenceCount == 1).Count());
|
||||
Assert.AreEqual(expected, osu.Dependencies.Get<DatabaseContextFactory>().Get().FileInfo.Count(f => f.ReferenceCount == 1));
|
||||
}
|
||||
|
||||
private static void ensureLoaded(OsuGameBase osu, int timeout = 60000)
|
||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Database
|
||||
/// <param name="obj">The object to use as a reference when negotiating a local instance.</param>
|
||||
/// <param name="lookupSource">An optional lookup source which will be used to query and populate a freshly retrieved replacement. If not provided, the refreshed object will still be returned but will not have any includes.</param>
|
||||
/// <typeparam name="T">A valid EF-stored type.</typeparam>
|
||||
protected virtual void Refresh<T>(ref T obj, IQueryable<T> lookupSource = null) where T : class, IHasPrimaryKey
|
||||
protected void Refresh<T>(ref T obj, IQueryable<T> lookupSource = null) where T : class, IHasPrimaryKey
|
||||
{
|
||||
using (var usage = ContextFactory.GetForWrite())
|
||||
{
|
||||
|
@ -14,6 +14,7 @@ using osu.Framework.Statistics;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Models;
|
||||
using osu.Game.Stores;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
@ -121,6 +122,10 @@ namespace osu.Game.Database
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
// clean up files after dropping any pending deletions.
|
||||
// in the future we may want to only do this when the game is idle, rather than on every startup.
|
||||
new RealmFileStore(this, storage).Cleanup();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -2,11 +2,8 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Framework.Logging;
|
||||
@ -31,13 +28,6 @@ namespace osu.Game.IO
|
||||
Store = new StorageBackedResourceStore(Storage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform a lookup query on available <see cref="FileInfo"/>s.
|
||||
/// </summary>
|
||||
/// <param name="query">The query.</param>
|
||||
/// <returns>Results from the provided query.</returns>
|
||||
public IEnumerable<FileInfo> QueryFiles(Expression<Func<FileInfo, bool>> query) => ContextFactory.Get().Set<FileInfo>().AsNoTracking().Where(f => f.ReferenceCount > 0).Where(query);
|
||||
|
||||
public FileInfo Add(Stream data, bool reference = true)
|
||||
{
|
||||
using (var usage = ContextFactory.GetForWrite())
|
||||
|
@ -24,7 +24,7 @@ using osu.Game.Rulesets.Scoring;
|
||||
|
||||
namespace osu.Game.Scoring
|
||||
{
|
||||
public class ScoreManager : IModelManager<ScoreInfo>, IModelImporter<ScoreInfo>, IModelFileManager<ScoreInfo, ScoreFileInfo>, IModelDownloader<IScoreInfo>
|
||||
public class ScoreManager : IModelManager<ScoreInfo>, IModelImporter<ScoreInfo>, IModelDownloader<IScoreInfo>
|
||||
{
|
||||
private readonly Scheduler scheduler;
|
||||
private readonly Func<BeatmapDifficultyCache> difficulties;
|
||||
@ -336,25 +336,6 @@ namespace osu.Game.Scoring
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IModelFileManager<in ScoreInfo,in ScoreFileInfo>
|
||||
|
||||
public void ReplaceFile(ScoreInfo model, ScoreFileInfo file, Stream contents, string filename = null)
|
||||
{
|
||||
scoreModelManager.ReplaceFile(model, file, contents, filename);
|
||||
}
|
||||
|
||||
public void DeleteFile(ScoreInfo model, ScoreFileInfo file)
|
||||
{
|
||||
scoreModelManager.DeleteFile(model, file);
|
||||
}
|
||||
|
||||
public void AddFile(ScoreInfo model, Stream contents, string filename)
|
||||
{
|
||||
scoreModelManager.AddFile(model, contents, filename);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IModelDownloader<IScoreInfo>
|
||||
|
||||
public event Action<ArchiveDownloadRequest<IScoreInfo>> DownloadBegan
|
||||
|
@ -86,9 +86,13 @@ namespace osu.Game.Stores
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
var realm = realmFactory.Context;
|
||||
Logger.Log(@"Beginning realm file store cleanup");
|
||||
|
||||
int totalFiles = 0;
|
||||
int removedFiles = 0;
|
||||
|
||||
// can potentially be run asynchronously, although we will need to consider operation order for disk deletion vs realm removal.
|
||||
using (var realm = realmFactory.CreateContext())
|
||||
using (var transaction = realm.BeginWrite())
|
||||
{
|
||||
// TODO: consider using a realm native query to avoid iterating all files (https://github.com/realm/realm-dotnet/issues/2659#issuecomment-927823707)
|
||||
@ -96,11 +100,14 @@ namespace osu.Game.Stores
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
totalFiles++;
|
||||
|
||||
if (file.BacklinksCount > 0)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
removedFiles++;
|
||||
Storage.Delete(file.GetStoragePath());
|
||||
realm.Remove(file);
|
||||
}
|
||||
@ -112,6 +119,8 @@ namespace osu.Game.Stores
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
Logger.Log($@"Finished realm file store cleanup ({removedFiles} of {totalFiles} deleted)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user