From 7e43b44e2444fa25fdfa2c50dc352ac561e96584 Mon Sep 17 00:00:00 2001 From: asesidaa <1061472754@qq.com> Date: Mon, 12 Sep 2022 17:29:29 +0800 Subject: [PATCH] Cache more on song data Remove unnecessary using --- SharedProject/Models/SongBestData.cs | 6 ++++++ TaikoWebUI/Pages/TaikoMode.razor | 10 +++++----- TaikoWebUI/Pages/TaikoMode.razor.cs | 9 +++++++++ TaikoWebUI/Program.cs | 3 --- TaikoWebUI/Services/GameDataService.cs | 4 ---- TaikoWebUI/Services/IGameDataService.cs | 6 +----- TaikoWebUI/Shared/Models/MusicDetail.cs | 4 +--- TaikoWebUI/Shared/Models/MusicInfoEntry.cs | 1 - TaikoWebUI/Shared/Models/MusicOrderEntry.cs | 1 - TaikoWebUI/TaikoWebUI.csproj | 3 +++ 10 files changed, 25 insertions(+), 22 deletions(-) diff --git a/SharedProject/Models/SongBestData.cs b/SharedProject/Models/SongBestData.cs index 003673b..ddfe54e 100644 --- a/SharedProject/Models/SongBestData.cs +++ b/SharedProject/Models/SongBestData.cs @@ -5,6 +5,12 @@ namespace SharedProject.Models; public class SongBestData { public uint SongId { get; set; } + + public SongGenre Genre { get; set; } + + public string MusicName { get; set; } = string.Empty; + + public string MusicArtist { get; set; } = string.Empty; public Difficulty Difficulty { get; set; } diff --git a/TaikoWebUI/Pages/TaikoMode.razor b/TaikoWebUI/Pages/TaikoMode.razor index 183a387..8764ab0 100644 --- a/TaikoWebUI/Pages/TaikoMode.razor +++ b/TaikoWebUI/Pages/TaikoMode.razor @@ -37,8 +37,8 @@ - @GameDataService.GetMusicNameBySongId(context.Item.SongId) - @GameDataService.GetMusicArtistBySongId(context.Item.SongId) + @context.Item.MusicName + @context.Item.MusicArtist @@ -56,12 +56,12 @@ - - - @GetGenreTitle(GameDataService.GetMusicGenreBySongId(context.Item.SongId)) + @GetGenreTitle(context.Item.Genre) diff --git a/TaikoWebUI/Pages/TaikoMode.razor.cs b/TaikoWebUI/Pages/TaikoMode.razor.cs index 72f561f..b0024d7 100644 --- a/TaikoWebUI/Pages/TaikoMode.razor.cs +++ b/TaikoWebUI/Pages/TaikoMode.razor.cs @@ -21,6 +21,15 @@ public partial class TaikoMode await base.OnInitializedAsync(); response = await Client.GetFromJsonAsync($"api/PlayData/{Baid}"); response.ThrowIfNull(); + + response.SongBestData.ForEach(data => + { + var songId = data.SongId; + data.Genre = GameDataService.GetMusicGenreBySongId(songId); + data.MusicName = GameDataService.GetMusicNameBySongId(songId); + data.MusicArtist = GameDataService.GetMusicArtistBySongId(songId); + }); + songBestDataMap = response.SongBestData.GroupBy(data => data.Difficulty) .ToDictionary(data => data.Key, data => data.ToList()); diff --git a/TaikoWebUI/Program.cs b/TaikoWebUI/Program.cs index 2271174..7821a3d 100644 --- a/TaikoWebUI/Program.cs +++ b/TaikoWebUI/Program.cs @@ -1,8 +1,5 @@ -using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using TaikoWebUI; using MudBlazor.Services; -using TaikoWebUI.Services; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); diff --git a/TaikoWebUI/Services/GameDataService.cs b/TaikoWebUI/Services/GameDataService.cs index a04832a..73544af 100644 --- a/TaikoWebUI/Services/GameDataService.cs +++ b/TaikoWebUI/Services/GameDataService.cs @@ -1,9 +1,5 @@ using System.Collections.Immutable; -using System.Net.Http.Json; -using SharedProject.Enums; -using SharedProject.Models; using TaikoWebUI.Shared.Models; -using Throw; namespace TaikoWebUI.Services; diff --git a/TaikoWebUI/Services/IGameDataService.cs b/TaikoWebUI/Services/IGameDataService.cs index 5f80fce..b3359ed 100644 --- a/TaikoWebUI/Services/IGameDataService.cs +++ b/TaikoWebUI/Services/IGameDataService.cs @@ -1,8 +1,4 @@ -using SharedProject.Enums; -using SharedProject.Models; -using TaikoWebUI.Shared.Models; - -namespace TaikoWebUI.Services; +namespace TaikoWebUI.Services; public interface IGameDataService { diff --git a/TaikoWebUI/Shared/Models/MusicDetail.cs b/TaikoWebUI/Shared/Models/MusicDetail.cs index 402e2eb..35cc2df 100644 --- a/TaikoWebUI/Shared/Models/MusicDetail.cs +++ b/TaikoWebUI/Shared/Models/MusicDetail.cs @@ -1,6 +1,4 @@ -using SharedProject.Enums; - -namespace TaikoWebUI.Shared.Models; +namespace TaikoWebUI.Shared.Models; public class MusicDetail { diff --git a/TaikoWebUI/Shared/Models/MusicInfoEntry.cs b/TaikoWebUI/Shared/Models/MusicInfoEntry.cs index c2b1dec..5bd1d6e 100644 --- a/TaikoWebUI/Shared/Models/MusicInfoEntry.cs +++ b/TaikoWebUI/Shared/Models/MusicInfoEntry.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using SharedProject.Enums; namespace TaikoWebUI.Shared.Models; diff --git a/TaikoWebUI/Shared/Models/MusicOrderEntry.cs b/TaikoWebUI/Shared/Models/MusicOrderEntry.cs index 5d9a694..0c3098a 100644 --- a/TaikoWebUI/Shared/Models/MusicOrderEntry.cs +++ b/TaikoWebUI/Shared/Models/MusicOrderEntry.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using SharedProject.Enums; namespace TaikoWebUI.Shared.Models; diff --git a/TaikoWebUI/TaikoWebUI.csproj b/TaikoWebUI/TaikoWebUI.csproj index fda0f91..46494c7 100644 --- a/TaikoWebUI/TaikoWebUI.csproj +++ b/TaikoWebUI/TaikoWebUI.csproj @@ -26,6 +26,9 @@ PreserveNewest + + PreserveNewest +