mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Add ability to lookup multiple users at once to UserLookupCache
This commit is contained in:
@ -27,6 +27,30 @@ namespace osu.Game.Database
|
|||||||
[ItemCanBeNull]
|
[ItemCanBeNull]
|
||||||
public Task<User> GetUserAsync(int userId, CancellationToken token = default) => GetAsync(userId, token);
|
public Task<User> GetUserAsync(int userId, CancellationToken token = default) => GetAsync(userId, token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform an API lookup on the specified users, populating a <see cref="User"/> model.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userIds">The users to lookup.</param>
|
||||||
|
/// <param name="token">An optional cancellation token.</param>
|
||||||
|
/// <returns>.</returns>
|
||||||
|
public Task<User[]> GetUsersAsync(int[] userIds, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var userLookupTasks = new List<Task<User>>();
|
||||||
|
|
||||||
|
foreach (var u in userIds)
|
||||||
|
{
|
||||||
|
userLookupTasks.Add(GetUserAsync(u, token).ContinueWith(task =>
|
||||||
|
{
|
||||||
|
if (!task.IsCompletedSuccessfully)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return task.Result;
|
||||||
|
}, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.WhenAll(userLookupTasks);
|
||||||
|
}
|
||||||
|
|
||||||
protected override async Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)
|
protected override async Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)
|
||||||
=> await queryUser(lookup).ConfigureAwait(false);
|
=> await queryUser(lookup).ConfigureAwait(false);
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
@ -61,7 +60,7 @@ namespace osu.Game.Screens.Spectate
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
getAllUsers().ContinueWith(users => Schedule(() =>
|
userLookupCache.GetUsersAsync(userIds.ToArray()).ContinueWith(users => Schedule(() =>
|
||||||
{
|
{
|
||||||
foreach (var u in users.Result)
|
foreach (var u in users.Result)
|
||||||
userMap[u.Id] = u;
|
userMap[u.Id] = u;
|
||||||
@ -77,24 +76,6 @@ namespace osu.Game.Screens.Spectate
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<User[]> getAllUsers()
|
|
||||||
{
|
|
||||||
var userLookupTasks = new List<Task<User>>();
|
|
||||||
|
|
||||||
foreach (var u in userIds)
|
|
||||||
{
|
|
||||||
userLookupTasks.Add(userLookupCache.GetUserAsync(u).ContinueWith(task =>
|
|
||||||
{
|
|
||||||
if (!task.IsCompletedSuccessfully)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return task.Result;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Task.WhenAll(userLookupTasks);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> e)
|
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> e)
|
||||||
{
|
{
|
||||||
if (!e.NewValue.TryGetTarget(out var beatmapSet))
|
if (!e.NewValue.TryGetTarget(out var beatmapSet))
|
||||||
|
Reference in New Issue
Block a user