From d9f8944e89c947f06996021fbd0d8dc6574282a5 Mon Sep 17 00:00:00 2001 From: FajsiEx Date: Tue, 14 Dec 2021 20:02:25 +0100 Subject: [PATCH] * rate limit the IR requests on songwheel further --- scripts/songselect/songwheel.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/songselect/songwheel.lua b/scripts/songselect/songwheel.lua index 23d1fa3..483b67a 100644 --- a/scripts/songselect/songwheel.lua +++ b/scripts/songselect/songwheel.lua @@ -119,7 +119,8 @@ local jacketCache = {} local top50diffs = {} -local isIrLeaderboardRequested = false -- if false, we will request it after the scroll transition finishes to prevent spamming the API +local isIrLeaderboardRequested = false; +local irRequestTimeout = 2 local irLeaderboard = {} local transitionScrollScale = 0; @@ -541,6 +542,10 @@ function drawLocalLeaderboard(diff) end function drawIrLeaderboard() + if #irLeaderboard == 0 then + return; + end + gfx.LoadSkinFont('Digital-Serial-Bold.ttf') gfx.FontSize(26) @@ -653,6 +658,8 @@ function refreshIrLeaderboard() return; end + irRequestTimeout = 2; + IR.Leaderboard(diff.hash, 'best', 4, onIrLeaderboardFetched) end @@ -856,7 +863,7 @@ draw_songwheel = function(x,y,w,h, deltaTime) gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_TOP) local debugScrollingUp= "FALSE" if scrollingUp then debugScrollingUp = "TRUE" end; - -- gfx.Text('S_I: ' .. selectedIndex .. ' // S_D: ' .. selectedDifficulty .. ' // S_UP: ' .. debugScrollingUp .. ' // AC_TS: ' .. transitionAfterscrollScale .. ' // L_TS: ' .. transitionLeaveScale, 8, 8); + gfx.Text('S_I: ' .. selectedIndex .. ' // S_D: ' .. selectedDifficulty .. ' // S_UP: ' .. debugScrollingUp .. ' // AC_TS: ' .. transitionAfterscrollScale .. ' // L_TS: ' .. transitionLeaveScale .. ' // IR_T: ' .. irRequestTimeout, 8, 8); gfx.ResetTransform(); end @@ -882,8 +889,10 @@ render = function (deltaTime) draw_songwheel((resX - fullX) / 2, 0, fullX, fullY, deltaTime); - if (transitionScrollScale >= 1) then + if (irRequestTimeout < 0) then refreshIrLeaderboard(); -- For explantion, check where isIrLeaderboardRequested is defined + else + irRequestTimeout = irRequestTimeout - deltaTime end end @@ -944,4 +953,6 @@ set_diff = function(newDiff) selectedDifficulty = newDiff; isIrLeaderboardRequested = false; + irLeaderboard = {} + irRequestTimeout = 2 end; \ No newline at end of file