1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 17:02:55 +08:00

revert changes

This commit is contained in:
Davran Dilshat 2021-09-05 15:49:48 +01:00
parent e78dc1bb4c
commit b1a995e0bb
4 changed files with 6 additions and 113 deletions

View File

@ -601,4 +601,4 @@ namespace osu.Game.Online.Chat
: channel.Id == Id;
}
}
}
}

View File

@ -263,7 +263,7 @@ namespace osu.Game
dependencies.Cache(fileStore = new FileStore(contextFactory, Storage));
// ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup()
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, API, contextFactory, Host, () => difficultyCache, LocalConfig, true));
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, API, contextFactory, Host, () => difficultyCache, LocalConfig));
dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, contextFactory, RulesetStore, API, Audio, Resources, Host, defaultBeatmap, true));
// this should likely be moved to ArchiveModelManager when another case appears where it is necessary

View File

@ -26,7 +26,7 @@ using osu.Game.Scoring.Legacy;
namespace osu.Game.Scoring
{
public partial class ScoreManager : DownloadableArchiveModelManager<ScoreInfo, ScoreFileInfo>
public class ScoreManager : DownloadableArchiveModelManager<ScoreInfo, ScoreFileInfo>
{
public override IEnumerable<string> HandledExtensions => new[] { ".osr" };
@ -43,23 +43,14 @@ namespace osu.Game.Scoring
[CanBeNull]
private readonly OsuConfigManager configManager;
[CanBeNull]
private readonly UserIdLookupCache userIdLookupCache;
private readonly IAPIProvider api;
public ScoreManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, IAPIProvider api, IDatabaseContextFactory contextFactory, IIpcHost importHost = null,
Func<BeatmapDifficultyCache> difficulties = null, OsuConfigManager configManager = null, bool performOnlineLookups = false)
Func<BeatmapDifficultyCache> difficulties = null, OsuConfigManager configManager = null)
: base(storage, contextFactory, api, new ScoreStore(contextFactory, storage), importHost)
{
this.rulesets = rulesets;
this.beatmaps = beatmaps;
this.difficulties = difficulties;
this.configManager = configManager;
this.api = api;
if (performOnlineLookups)
userIdLookupCache = new UserIdLookupCache(api);
}
protected override ScoreInfo CreateModel(ArchiveReader archive)
@ -81,21 +72,8 @@ namespace osu.Game.Scoring
}
}
protected override async Task Populate(ScoreInfo model, ArchiveReader archive, CancellationToken cancellationToken = default)
{
// These scores only provide the user's username but we need the user's ID too.
if (model.UserID <= 1 && model.UserString != null && userIdLookupCache != null)
{
try
{
model.UserID = await userIdLookupCache.GetUserIdAsync(model.UserString, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
LogForModel(model, $"Online retrieval failed for {model.User} ({e.Message})", e);
}
}
}
protected override Task Populate(ScoreInfo model, ArchiveReader archive, CancellationToken cancellationToken = default)
=> Task.CompletedTask;
protected override void ExportModelTo(ScoreInfo model, Stream outputStream)
{

View File

@ -1,85 +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.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Database;
namespace osu.Game.Scoring
{
public partial class ScoreManager
{
private class UserIdLookupCache : MemoryCachingComponent<string, int>
{
private readonly IAPIProvider api;
public UserIdLookupCache(IAPIProvider api)
{
this.api = api;
}
/// <summary>
/// Perform an API lookup on the specified username, returning the associated ID.
/// </summary>
/// <param name="username">The username to lookup.</param>
/// <param name="token">An optional cancellation token.</param>
/// <returns>The user ID, or 1 if the user does not exist or the request could not be satisfied.</returns>
public Task<int> GetUserIdAsync(string username, CancellationToken token = default) => GetAsync(username, token);
protected override async Task<int> ComputeValueAsync(string lookup, CancellationToken token = default)
=> await queryUserId(lookup).ConfigureAwait(false);
private readonly Queue<(string username, TaskCompletionSource<int>)> pendingUserTasks = new Queue<(string, TaskCompletionSource<int>)>();
private Task pendingRequestTask;
private readonly object taskAssignmentLock = new object();
private Task<int> queryUserId(string username)
{
lock (taskAssignmentLock)
{
var tcs = new TaskCompletionSource<int>();
// Add to the queue.
pendingUserTasks.Enqueue((username, tcs));
// Create a request task if there's not already one.
if (pendingRequestTask == null)
createNewTask();
return tcs.Task;
}
}
private void performLookup()
{
(string username, TaskCompletionSource<int> task) next;
lock (taskAssignmentLock)
{
next = pendingUserTasks.Dequeue();
}
var request = new GetUserRequest(next.username);
// rather than queueing, we maintain our own single-threaded request stream.
// todo: we probably want retry logic here.
api.Perform(request);
// Create a new request task if there's still more users to query.
lock (taskAssignmentLock)
{
pendingRequestTask = null;
if (pendingUserTasks.Count > 0)
createNewTask();
}
next.task.SetResult(request.Result?.Id ?? 1);
}
private void createNewTask() => pendingRequestTask = Task.Run(performLookup);
}
}
}