From f43f6ed4626f282f3ff3036ca94f5286df544705 Mon Sep 17 00:00:00 2001 From: Kinsi Date: Sat, 26 Jun 2021 10:40:38 +0200 Subject: [PATCH] Do less unnecessary UI refreshing --- UI/DownloadHistoryView.cs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/UI/DownloadHistoryView.cs b/UI/DownloadHistoryView.cs index 0c3547b..5309738 100644 --- a/UI/DownloadHistoryView.cs +++ b/UI/DownloadHistoryView.cs @@ -6,6 +6,7 @@ using IPA.Utilities; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using TMPro; @@ -80,10 +81,17 @@ public async void ProcessDownloads(bool forceTableReload = false) { await Task.Run(async () => { try { + var updateRateLimiter = new Stopwatch(); + updateRateLimiter.Start(); + await SongDownloader.BeatmapDownload(firstEntry, BSSFlowCoordinator.closeCancelSource.Token, (float progress) => { firstEntry.statusDetails = string.Format("({0:0%}{1})", progress, firstEntry.retries == 0 ? "" : $", retry #{firstEntry.retries} / "); firstEntry.downloadProgress = progress; + if(updateRateLimiter.ElapsedMilliseconds < 0.05) + return; + updateRateLimiter.Restart(); + IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew(firstEntry.UpdateProgress); }); @@ -100,7 +108,7 @@ await SongDownloader.BeatmapDownload(firstEntry, BSSFlowCoordinator.closeCancelS }); if(firstEntry.status == DownloadHistoryEntry.DownloadStatus.Downloaded) { - BSSFlowCoordinator.songListView.RefreshTable(); + BSSFlowCoordinator.songListView.songList.RefreshCells(false, true); // NESTING HELLLL var selectedSongView = BSSFlowCoordinator.songListView.selectedSongView; @@ -111,14 +119,22 @@ await SongDownloader.BeatmapDownload(firstEntry, BSSFlowCoordinator.closeCancelS ProcessDownloads(true); } - public void RefreshTable(bool fullReload = true) { - BSMLStuff.UnleakTable(downloadHistoryTable.gameObject); + RatelimitCoroutine limitedFullTableReload; - downloadHistoryData.data = downloadList.OrderBy(x => x.orderValue).Cast().ToList(); + void Awake() { + limitedFullTableReload = new RatelimitCoroutine(() => { + BSMLStuff.UnleakTable(downloadHistoryTable.gameObject); + + downloadHistoryData.data = downloadList.OrderBy(x => x.orderValue).Cast().ToList(); - if(fullReload) { downloadHistoryTable.ReloadData(); downloadHistoryTable.ScrollToCellWithIdx(0, TableView.ScrollPositionType.Beginning, false); + }, 0.2f); + } + + public void RefreshTable(bool fullReload = true) { + if(fullReload) { + StartCoroutine(limitedFullTableReload.Call()); } else { downloadHistoryTable.RefreshCells(false, true); }