1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00
osu-lazer/osu.Game/Database/UserLookupCache.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.8 KiB
C#
Raw Normal View History

2020-11-06 15:38:57 +08:00
// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-11-06 15:38:57 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
2020-11-06 15:38:57 +08:00
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
2020-11-06 15:38:57 +08:00
namespace osu.Game.Database
{
public partial class UserLookupCache : OnlineLookupCache<int, APIUser, GetUsersRequest>
2020-11-06 15:38:57 +08:00
{
/// <summary>
/// Perform an API lookup on the specified user, populating a <see cref="APIUser"/> model.
/// </summary>
/// <param name="userId">The user to lookup.</param>
/// <param name="token">An optional cancellation token.</param>
/// <returns>The populated user, or null if the user does not exist or the request could not be satisfied.</returns>
[ItemCanBeNull]
public Task<APIUser> GetUserAsync(int userId, CancellationToken token = default) => LookupAsync(userId, token);
2020-11-06 15:38:57 +08:00
/// <summary>
/// Perform an API lookup on the specified users, populating a <see cref="APIUser"/> model.
/// </summary>
/// <param name="userIds">The users to lookup.</param>
/// <param name="token">An optional cancellation token.</param>
/// <returns>The populated users. May include null results for failed retrievals.</returns>
public Task<APIUser[]> GetUsersAsync(int[] userIds, CancellationToken token = default) => LookupAsync(userIds, token);
2020-11-17 09:57:11 +08:00
protected override GetUsersRequest CreateRequest(IEnumerable<int> ids) => new GetUsersRequest(ids.ToArray());
protected override IEnumerable<APIUser> RetrieveResults(GetUsersRequest request) => request.Response?.Users;
2020-11-06 15:38:57 +08:00
}
}