1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:47:28 +08:00

Remove EF FileStore

This commit is contained in:
Dean Herbert 2021-12-01 16:10:50 +09:00
parent 3ecd889fef
commit 116f35c52a
4 changed files with 4 additions and 134 deletions

View File

@ -16,7 +16,6 @@ using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Input;
using osu.Game.Input.Bindings;
using osu.Game.IO;
using osu.Game.Online.API;
using osu.Game.Online.Chat;
using osu.Game.Overlays;
@ -25,6 +24,7 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Menu;
using osu.Game.Skinning;
using osu.Game.Stores;
using osu.Game.Utils;
namespace osu.Game.Tests.Visual.Navigation
@ -69,7 +69,7 @@ namespace osu.Game.Tests.Visual.Navigation
typeof(ISkinSource),
typeof(IAPIProvider),
typeof(RulesetStore),
typeof(FileStore),
typeof(RealmFileStore),
typeof(ScoreManager),
typeof(BeatmapManager),
typeof(IRulesetConfigCache),

View File

@ -24,6 +24,7 @@ using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets;
using osu.Game.Skinning;
using osu.Game.Stores;
namespace osu.Game.Beatmaps
{
@ -42,7 +43,7 @@ namespace osu.Game.Beatmaps
public BeatmapManager(Storage storage, RealmContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> gameResources, GameHost host = null, WorkingBeatmap defaultBeatmap = null, bool performOnlineLookups = false)
{
var userResources = new FileStore(contextFactory, storage).Store;
var userResources = new RealmFileStore(contextFactory, storage).Store;
BeatmapTrackStore = audioManager.GetTrackStore(userResources);

View File

@ -1,125 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.IO;
using System.Linq;
using osu.Framework.Extensions;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Database;
using osu.Game.Extensions;
namespace osu.Game.IO
{
/// <summary>
/// Handles the Store and retrieval of Files/FileSets to the database backing
/// </summary>
public class FileStore : DatabaseBackedStore
{
public readonly IResourceStore<byte[]> Store;
public new Storage Storage => base.Storage;
public FileStore(IDatabaseContextFactory contextFactory, Storage storage)
: base(contextFactory, storage.GetStorageForDirectory(@"files"))
{
Store = new StorageBackedResourceStore(Storage);
}
public FileInfo Add(Stream data, bool reference = true)
{
using (var usage = ContextFactory.GetForWrite())
{
string hash = data.ComputeSHA2Hash();
var existing = usage.Context.FileInfo.FirstOrDefault(f => f.Hash == hash);
var info = existing ?? new FileInfo { Hash = hash };
string path = info.GetStoragePath();
// we may be re-adding a file to fix missing store entries.
bool requiresCopy = !Storage.Exists(path);
if (!requiresCopy)
{
// even if the file already exists, check the existing checksum for safety.
using (var stream = Storage.GetStream(path))
requiresCopy |= stream.ComputeSHA2Hash() != hash;
}
if (requiresCopy)
{
data.Seek(0, SeekOrigin.Begin);
using (var output = Storage.GetStream(path, FileAccess.Write))
data.CopyTo(output);
data.Seek(0, SeekOrigin.Begin);
}
if (reference || existing == null)
Reference(info);
return info;
}
}
public void Reference(params FileInfo[] files)
{
if (files.Length == 0) return;
using (var usage = ContextFactory.GetForWrite())
{
var context = usage.Context;
foreach (var f in files.GroupBy(f => f.ID))
{
var refetch = context.Find<FileInfo>(f.First().ID) ?? f.First();
refetch.ReferenceCount += f.Count();
context.FileInfo.Update(refetch);
}
}
}
public void Dereference(params FileInfo[] files)
{
if (files.Length == 0) return;
using (var usage = ContextFactory.GetForWrite())
{
var context = usage.Context;
foreach (var f in files.GroupBy(f => f.ID))
{
var refetch = context.FileInfo.Find(f.Key);
refetch.ReferenceCount -= f.Count();
context.FileInfo.Update(refetch);
}
}
}
public override void Cleanup()
{
using (var usage = ContextFactory.GetForWrite())
{
var context = usage.Context;
foreach (var f in context.FileInfo.Where(f => f.ReferenceCount < 1))
{
try
{
Storage.Delete(f.GetStoragePath());
context.FileInfo.Remove(f);
}
catch (Exception e)
{
Logger.Error(e, $@"Could not delete beatmap {f}");
}
}
}
}
}
}

View File

@ -143,8 +143,6 @@ namespace osu.Game
private UserLookupCache userCache;
private BeatmapLookupCache beatmapCache;
private FileStore fileStore;
private RulesetConfigCache rulesetConfigCache;
private SpectatorClient spectatorClient;
@ -226,8 +224,6 @@ namespace osu.Game
var defaultBeatmap = new DummyWorkingBeatmap(Audio, Textures);
dependencies.Cache(fileStore = new FileStore(contextFactory, Storage));
dependencies.Cache(RulesetStore = new RulesetStore(realmFactory, Storage));
// ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup()
@ -285,8 +281,6 @@ namespace osu.Game
dependencies.CacheAs<IBindable<WorkingBeatmap>>(Beatmap);
dependencies.CacheAs(Beatmap);
fileStore.Cleanup();
// add api components to hierarchy.
if (API is APIAccess apiAccess)
AddInternal(apiAccess);