This repository has been archived by the owner on Nov 6, 2022. It is now read-only.
forked from starfish23/mangafeed
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add throttling when restoring E-Hentai/ExHentai galleries.
- Loading branch information
1 parent
6ada3cb
commit 39e0d43
Showing
6 changed files
with
76 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package exh.eh | ||
|
||
class EHentaiThrottleManager(private val max: Int = THROTTLE_MAX, | ||
private val inc: Int = THROTTLE_INC) { | ||
private var lastThrottleTime: Long = 0 | ||
var throttleTime: Long = 0 | ||
private set | ||
|
||
fun throttle() { | ||
//Throttle requests if necessary | ||
val now = System.currentTimeMillis() | ||
val timeDiff = now - lastThrottleTime | ||
if(timeDiff < throttleTime) | ||
Thread.sleep(throttleTime - timeDiff) | ||
|
||
if(throttleTime < max) | ||
throttleTime += inc | ||
|
||
lastThrottleTime = System.currentTimeMillis() | ||
} | ||
|
||
fun resetThrottle() { | ||
lastThrottleTime = 0 | ||
throttleTime = 0 | ||
} | ||
|
||
companion object { | ||
const val THROTTLE_MAX = 5500 | ||
const val THROTTLE_INC = 20 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters