2021-11-30 10:27:43 +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
|
|
|
|
|
2021-11-30 10:27:43 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
|
|
|
namespace osu.Game.Database
|
|
|
|
{
|
2021-12-21 09:33:28 +00:00
|
|
|
public class BeatmapLookupCache : OnlineLookupCache<int, APIBeatmap, GetBeatmapsRequest>
|
2021-11-30 10:27:43 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Perform an API lookup on the specified beatmap, populating a <see cref="APIBeatmap"/> model.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="beatmapId">The beatmap to lookup.</param>
|
|
|
|
/// <param name="token">An optional cancellation token.</param>
|
|
|
|
/// <returns>The populated beatmap, or null if the beatmap does not exist or the request could not be satisfied.</returns>
|
|
|
|
[ItemCanBeNull]
|
2021-12-21 09:33:28 +00:00
|
|
|
public Task<APIBeatmap> GetBeatmapAsync(int beatmapId, CancellationToken token = default) => LookupAsync(beatmapId, token);
|
2021-11-30 10:27:43 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Perform an API lookup on the specified beatmaps, populating a <see cref="APIBeatmap"/> model.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="beatmapIds">The beatmaps to lookup.</param>
|
|
|
|
/// <param name="token">An optional cancellation token.</param>
|
|
|
|
/// <returns>The populated beatmaps. May include null results for failed retrievals.</returns>
|
2021-12-21 09:33:28 +00:00
|
|
|
public Task<APIBeatmap[]> GetBeatmapsAsync(int[] beatmapIds, CancellationToken token = default) => LookupAsync(beatmapIds, token);
|
2021-11-30 10:27:43 +00:00
|
|
|
|
2021-12-21 09:33:28 +00:00
|
|
|
protected override GetBeatmapsRequest CreateRequest(IEnumerable<int> ids) => new GetBeatmapsRequest(ids.ToArray());
|
2021-11-30 10:27:43 +00:00
|
|
|
|
2021-12-21 09:33:28 +00:00
|
|
|
protected override IEnumerable<APIBeatmap> RetrieveResults(GetBeatmapsRequest request) => request.Response?.Beatmaps;
|
2021-11-30 10:27:43 +00:00
|
|
|
}
|
|
|
|
}
|