2020-11-06 07:38:57 +00: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 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-11-06 07:38:57 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-12-28 11:13:24 +00:00
|
|
|
using JetBrains.Annotations;
|
2020-11-06 07:38:57 +00:00
|
|
|
using osu.Game.Online.API.Requests;
|
2021-11-04 09:02:44 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-11-06 07:38:57 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Database
|
|
|
|
{
|
2021-12-21 09:33:28 +00:00
|
|
|
public partial class UserLookupCache : OnlineLookupCache<int, APIUser, GetUsersRequest>
|
2020-11-06 07:38:57 +00:00
|
|
|
{
|
2020-12-28 11:05:48 +00:00
|
|
|
/// <summary>
|
2021-11-04 09:02:44 +00:00
|
|
|
/// Perform an API lookup on the specified user, populating a <see cref="APIUser"/> model.
|
2020-12-28 11:05:48 +00:00
|
|
|
/// </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>
|
2020-12-28 11:13:24 +00:00
|
|
|
[ItemCanBeNull]
|
2021-12-21 09:33:28 +00:00
|
|
|
public Task<APIUser> GetUserAsync(int userId, CancellationToken token = default) => LookupAsync(userId, token);
|
2020-11-06 07:38:57 +00:00
|
|
|
|
2021-07-05 10:56:16 +00:00
|
|
|
/// <summary>
|
2021-11-04 09:02:44 +00:00
|
|
|
/// Perform an API lookup on the specified users, populating a <see cref="APIUser"/> model.
|
2021-07-05 10:56:16 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="userIds">The users to lookup.</param>
|
|
|
|
/// <param name="token">An optional cancellation token.</param>
|
2021-07-05 12:30:24 +00:00
|
|
|
/// <returns>The populated users. May include null results for failed retrievals.</returns>
|
2021-12-21 09:33:28 +00:00
|
|
|
public Task<APIUser[]> GetUsersAsync(int[] userIds, CancellationToken token = default) => LookupAsync(userIds, token);
|
2020-11-17 01:57:11 +00:00
|
|
|
|
2021-12-21 09:33:28 +00:00
|
|
|
protected override GetUsersRequest CreateRequest(IEnumerable<int> ids) => new GetUsersRequest(ids.ToArray());
|
2020-11-16 11:35:22 +00:00
|
|
|
|
2021-12-21 09:33:28 +00:00
|
|
|
protected override IEnumerable<APIUser> RetrieveResults(GetUsersRequest request) => request.Response?.Users;
|
2020-11-06 07:38:57 +00:00
|
|
|
}
|
|
|
|
}
|