From 9e49e278331d5b873ee733ccc12282bc0580270b Mon Sep 17 00:00:00 2001 From: BtbN Date: Thu, 13 Jun 2019 22:02:41 +0200 Subject: [PATCH] Optimize output speed a bit --- ClanServer/Controllers/L44/Gametop.cs | 38 ++++++++++++------- .../Formatters/EamuseXrpcOutputFormatter.cs | 4 +- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/ClanServer/Controllers/L44/Gametop.cs b/ClanServer/Controllers/L44/Gametop.cs index 469f6d5..f09784c 100644 --- a/ClanServer/Controllers/L44/Gametop.cs +++ b/ClanServer/Controllers/L44/Gametop.cs @@ -473,9 +473,19 @@ namespace ClanServer.Controllers.L44 if (profile == null) return NotFound(); - var scoreGroups = ctx.JubeatHighscores + List scores = await ctx.JubeatHighscores .Where(s => s.ProfileID == profile.ID) - .GroupBy(s => s.MusicID); + .ToListAsync(); + + var scoreGroups = new Dictionary(); + + foreach (var score in scores) + { + if (!scoreGroups.ContainsKey(score.MusicID)) + scoreGroups.Add(score.MusicID, new JubeatHighscore[3]); + + scoreGroups[score.MusicID][score.Seq] = score; + } XElement mdataList = new XElement("mdata_list"); @@ -489,17 +499,19 @@ namespace ClanServer.Controllers.L44 var exCnt = new int[3]; var bars = new[] { new byte[30], new byte[30], new byte[30] }; - foreach (JubeatHighscore highscore in scoreGroup) + for (int seq = 0; seq < 3; ++seq) { - int seq = highscore.Seq; + JubeatHighscore score = scoreGroup.Value[seq]; + if (score == null) + continue; - scoreRes[seq] = highscore.Score; - clearRes[seq] = highscore.Clear; - playCnt[seq] = highscore.PlayCount; - clearCnt[seq] = highscore.ClearCount; - fcCnt[seq] = highscore.FcCount; - exCnt[seq] = highscore.ExcCount; - bars[seq] = highscore.Bar; + scoreRes[seq] = score.Score; + clearRes[seq] = score.Clear; + playCnt[seq] = score.PlayCount; + clearCnt[seq] = score.ClearCount; + fcCnt[seq] = score.FcCount; + exCnt[seq] = score.ExcCount; + bars[seq] = score.Bar; } mdataList.Add(new XElement("music", new XAttribute("music_id", scoreGroup.Key), @@ -509,9 +521,9 @@ namespace ClanServer.Controllers.L44 new KS32("clear_cnt", clearCnt), new KS32("fc_cnt", fcCnt), new KS32("ex_cnt", exCnt), - new KU8("bar", bars[2]).AddAttr("seq", 2), new KU8("bar", bars[0]).AddAttr("seq", 0), - new KU8("bar", bars[1]).AddAttr("seq", 1) + new KU8("bar", bars[1]).AddAttr("seq", 1), + new KU8("bar", bars[2]).AddAttr("seq", 2) )); } diff --git a/ClanServer/Formatters/EamuseXrpcOutputFormatter.cs b/ClanServer/Formatters/EamuseXrpcOutputFormatter.cs index 2e274e2..ea397eb 100644 --- a/ClanServer/Formatters/EamuseXrpcOutputFormatter.cs +++ b/ClanServer/Formatters/EamuseXrpcOutputFormatter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Threading.Tasks; @@ -39,7 +39,7 @@ namespace ClanServer.Formatters string algo = "none"; - var compressed = LZ77.Compress(resData).ToArray(); + var compressed = LZ77.Compress(resData, 32).ToArray(); if (compressed.Length < resData.Length) { resData = compressed;