From 4e17634ee27ab7dfc33753c1750d8f91e6e2b206 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 2 Nov 2020 17:31:04 +0900 Subject: [PATCH] Add (temporary) local user cache to avoid re-querying API each display --- .../Dashboard/CurrentlyPlayingDisplay.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Dashboard/CurrentlyPlayingDisplay.cs b/osu.Game/Overlays/Dashboard/CurrentlyPlayingDisplay.cs index d71e582c05..b461da4476 100644 --- a/osu.Game/Overlays/Dashboard/CurrentlyPlayingDisplay.cs +++ b/osu.Game/Overlays/Dashboard/CurrentlyPlayingDisplay.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . 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 user_cache = new Dictionary(); + 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()) + foreach (int userId in e.NewItems.OfType()) { - 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;