mirror of
https://github.com/osukey/osukey.git
synced 2025-05-22 14:07:38 +09:00
Remove custom hash function flow
This commit is contained in:
parent
2f8290831a
commit
f11fe54385
@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@ -12,7 +14,6 @@ using NUnit.Framework;
|
|||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Extensions.ObjectExtensions;
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
@ -28,8 +29,6 @@ using SharpCompress.Archives.Zip;
|
|||||||
using SharpCompress.Common;
|
using SharpCompress.Common;
|
||||||
using SharpCompress.Writers.Zip;
|
using SharpCompress.Writers.Zip;
|
||||||
|
|
||||||
#nullable enable
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Database
|
namespace osu.Game.Tests.Database
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
@ -622,7 +621,7 @@ namespace osu.Game.Tests.Database
|
|||||||
using var importer = new BeatmapModelManager(realm, storage);
|
using var importer = new BeatmapModelManager(realm, storage);
|
||||||
using var store = new RealmRulesetStore(realm, storage);
|
using var store = new RealmRulesetStore(realm, storage);
|
||||||
|
|
||||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
var imported = await LoadOszIntoStore(importer, realm.Realm, batchImport: true);
|
||||||
|
|
||||||
deleteBeatmapSet(imported, realm.Realm);
|
deleteBeatmapSet(imported, realm.Realm);
|
||||||
|
|
||||||
@ -678,7 +677,7 @@ namespace osu.Game.Tests.Database
|
|||||||
{
|
{
|
||||||
RunTestWithRealmAsync(async (realm, storage) =>
|
RunTestWithRealmAsync(async (realm, storage) =>
|
||||||
{
|
{
|
||||||
using var importer = new NonOptimisedBeatmapImporter(realm, storage);
|
using var importer = new BeatmapModelManager(realm, storage);
|
||||||
using var store = new RealmRulesetStore(realm, storage);
|
using var store = new RealmRulesetStore(realm, storage);
|
||||||
|
|
||||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||||
@ -960,11 +959,11 @@ namespace osu.Game.Tests.Database
|
|||||||
return realm.All<BeatmapSetInfo>().FirstOrDefault(beatmapSet => beatmapSet.ID == importedSet!.ID);
|
return realm.All<BeatmapSetInfo>().FirstOrDefault(beatmapSet => beatmapSet.ID == importedSet!.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<BeatmapSetInfo> LoadOszIntoStore(BeatmapImporter importer, Realm realm, string? path = null, bool virtualTrack = false)
|
public static async Task<BeatmapSetInfo> LoadOszIntoStore(BeatmapImporter importer, Realm realm, string? path = null, bool virtualTrack = false, bool batchImport = false)
|
||||||
{
|
{
|
||||||
string? temp = path ?? TestResources.GetTestBeatmapForImport(virtualTrack);
|
string? temp = path ?? TestResources.GetTestBeatmapForImport(virtualTrack);
|
||||||
|
|
||||||
var importedSet = await importer.Import(new ImportTask(temp));
|
var importedSet = await importer.Import(new ImportTask(temp), batchImport);
|
||||||
|
|
||||||
Assert.NotNull(importedSet);
|
Assert.NotNull(importedSet);
|
||||||
Debug.Assert(importedSet != null);
|
Debug.Assert(importedSet != null);
|
||||||
@ -1081,15 +1080,5 @@ namespace osu.Game.Tests.Database
|
|||||||
|
|
||||||
Assert.Fail(failureMessage);
|
Assert.Fail(failureMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NonOptimisedBeatmapImporter : BeatmapImporter
|
|
||||||
{
|
|
||||||
public NonOptimisedBeatmapImporter(RealmAccess realm, Storage storage)
|
|
||||||
: base(realm, storage)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool HasCustomHashFunction => true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,6 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
private const string unknown_creator_string = @"Unknown";
|
private const string unknown_creator_string = @"Unknown";
|
||||||
|
|
||||||
protected override bool HasCustomHashFunction => true;
|
|
||||||
|
|
||||||
protected override void Populate(SkinInfo model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
|
protected override void Populate(SkinInfo model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var skinInfoFile = model.Files.SingleOrDefault(f => f.Filename == skin_info_file);
|
var skinInfoFile = model.Files.SingleOrDefault(f => f.Filename == skin_info_file);
|
||||||
|
@ -257,7 +257,7 @@ namespace osu.Game.Stores
|
|||||||
bool checkedExisting = false;
|
bool checkedExisting = false;
|
||||||
TModel? existing = null;
|
TModel? existing = null;
|
||||||
|
|
||||||
if (quickSkipIfExisting && archive != null && !HasCustomHashFunction)
|
if (quickSkipIfExisting && archive != null)
|
||||||
{
|
{
|
||||||
// this is a fast bail condition to improve large import performance.
|
// this is a fast bail condition to improve large import performance.
|
||||||
item.Hash = computeHashFast(archive);
|
item.Hash = computeHashFast(archive);
|
||||||
@ -373,19 +373,13 @@ namespace osu.Game.Stores
|
|||||||
Logger.Log($"{prefix} {message}", LoggingTarget.Database);
|
Logger.Log($"{prefix} {message}", LoggingTarget.Database);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether the implementation overrides <see cref="ComputeHash"/> with a custom implementation.
|
|
||||||
/// Custom hash implementations must bypass the early exit in the import flow (see <see cref="computeHashFast"/> usage).
|
|
||||||
/// </summary>
|
|
||||||
protected virtual bool HasCustomHashFunction => false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a SHA-2 hash from the provided archive based on file content of all files matching <see cref="HashableFileTypes"/>.
|
/// Create a SHA-2 hash from the provided archive based on file content of all files matching <see cref="HashableFileTypes"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// In the case of no matching files, a hash will be generated from the passed archive's <see cref="ArchiveReader.Name"/>.
|
/// In the case of no matching files, a hash will be generated from the passed archive's <see cref="ArchiveReader.Name"/>.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected virtual string ComputeHash(TModel item)
|
protected string ComputeHash(TModel item)
|
||||||
{
|
{
|
||||||
// for now, concatenate all hashable files in the set to create a unique hash.
|
// for now, concatenate all hashable files in the set to create a unique hash.
|
||||||
MemoryStream hashable = new MemoryStream();
|
MemoryStream hashable = new MemoryStream();
|
||||||
|
@ -147,7 +147,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
protected override BeatmapModelManager CreateBeatmapModelManager(Storage storage, RealmAccess realm, RulesetStore rulesets, BeatmapOnlineLookupQueue onlineLookupQueue)
|
protected override BeatmapModelManager CreateBeatmapModelManager(Storage storage, RealmAccess realm, RulesetStore rulesets, BeatmapOnlineLookupQueue onlineLookupQueue)
|
||||||
{
|
{
|
||||||
return new TestBeatmapModelManager(storage, realm, onlineLookupQueue);
|
return new BeatmapModelManager(realm, storage, onlineLookupQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override WorkingBeatmapCache CreateWorkingBeatmapCache(AudioManager audioManager, IResourceStore<byte[]> resources, IResourceStore<byte[]> storage, WorkingBeatmap defaultBeatmap, GameHost host)
|
protected override WorkingBeatmapCache CreateWorkingBeatmapCache(AudioManager audioManager, IResourceStore<byte[]> resources, IResourceStore<byte[]> storage, WorkingBeatmap defaultBeatmap, GameHost host)
|
||||||
@ -181,17 +181,6 @@ namespace osu.Game.Tests.Visual
|
|||||||
=> testBeatmapManager.TestBeatmap;
|
=> testBeatmapManager.TestBeatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class TestBeatmapModelManager : BeatmapModelManager
|
|
||||||
{
|
|
||||||
public TestBeatmapModelManager(Storage storage, RealmAccess databaseAccess, BeatmapOnlineLookupQueue beatmapOnlineLookupQueue)
|
|
||||||
: base(databaseAccess, storage, beatmapOnlineLookupQueue)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string ComputeHash(BeatmapSetInfo item)
|
|
||||||
=> string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Save(BeatmapInfo info, IBeatmap beatmapContent, ISkin beatmapSkin = null)
|
public override void Save(BeatmapInfo info, IBeatmap beatmapContent, ISkin beatmapSkin = null)
|
||||||
{
|
{
|
||||||
// don't actually care about saving for this context.
|
// don't actually care about saving for this context.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user