1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-23 01:37:31 +08:00

Add (temporary) local user cache to avoid re-querying API each display

This commit is contained in:
Dean Herbert 2020-11-02 17:31:04 +09:00
parent 414f65c1ef
commit 4e17634ee2

View File

@ -1,6 +1,7 @@
// 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.Collections.Specialized;
using System.Linq;
using osu.Framework.Allocation;
@ -43,6 +44,9 @@ namespace osu.Game.Overlays.Dashboard
[Resolved]
private IAPIProvider api { get; set; }
// temporary, should be game-global but i don't want to add more manager classes for now.
private static readonly Dictionary<int, User> user_cache = new Dictionary<int, User>();
protected override void LoadComplete()
{
base.LoadComplete();
@ -53,15 +57,24 @@ namespace osu.Game.Overlays.Dashboard
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (var u in e.NewItems.OfType<int>())
foreach (int userId in e.NewItems.OfType<int>())
{
var request = new GetUserRequest(u);
request.Success += user => Schedule(() =>
if (user_cache.TryGetValue(userId, out var user))
{
if (playingUsers.Contains((int)user.Id))
userFlow.Add(createUserPanel(user));
});
addUser(user);
continue;
}
var request = new GetUserRequest(userId);
request.Success += u => Schedule(() => addUser(u));
api.Queue(request);
void addUser(User u)
{
user_cache[userId] = u;
if (playingUsers.Contains(userId))
userFlow.Add(createUserPanel(u));
}
}
break;