mirror of
https://github.com/InsanusMokrassar/SauceNaoAPI.git
synced 2024-11-26 16:28:42 +00:00
fixes
This commit is contained in:
parent
51957eb369
commit
8c49e60dec
@ -1,9 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.SauceNaoAPI.additional
|
package com.github.insanusmokrassar.SauceNaoAPI.additional
|
||||||
|
|
||||||
|
import com.soywiz.klock.TimeSpan
|
||||||
|
|
||||||
typealias AccountType = Int
|
typealias AccountType = Int
|
||||||
const val defaultAccountType: AccountType = 1 // "basic"
|
const val defaultAccountType: AccountType = 1 // "basic"
|
||||||
|
|
||||||
typealias UserId = Int
|
typealias UserId = Int
|
||||||
|
|
||||||
const val SHORT_TIME_RECALCULATING_MILLIS = 30.0 * 1000
|
val SHORT_TIME_RECALCULATING_MILLIS = TimeSpan(30.0 * 1000)
|
||||||
const val LONG_TIME_RECALCULATING_MILLIS = 24.0 * 60 * 60 * 1000
|
val LONG_TIME_RECALCULATING_MILLIS = TimeSpan(24.0 * 60 * 60 * 1000)
|
||||||
|
@ -43,11 +43,11 @@ class RequestQuotaManager (
|
|||||||
shortQuota = min(newShortQuota, shortMaxQuota)
|
shortQuota = min(newShortQuota, shortMaxQuota)
|
||||||
|
|
||||||
when {
|
when {
|
||||||
longQuota < 1 -> (timeManager.getMostOldestInLongPeriod() ?: DateTime.now()).unixMillisLong + LONG_TIME_RECALCULATING_MILLIS.toLong()
|
longQuota < 1 -> (timeManager.getMostOldestInLongPeriod() ?: DateTime.now()) + LONG_TIME_RECALCULATING_MILLIS
|
||||||
shortQuota < 1 -> (timeManager.getMostOldestInShortPeriod() ?: DateTime.now()).unixMillisLong + SHORT_TIME_RECALCULATING_MILLIS.toLong()
|
shortQuota < 1 -> (timeManager.getMostOldestInShortPeriod() ?: DateTime.now()) + SHORT_TIME_RECALCULATING_MILLIS
|
||||||
else -> null
|
else -> null
|
||||||
} ?.also {
|
} ?.also {
|
||||||
delay((it - DateTime.now().unixMillisLong))
|
delay((it - DateTime.now()).millisecondsLong)
|
||||||
shortQuota = max(shortQuota, 1)
|
shortQuota = max(shortQuota, 1)
|
||||||
longQuota = max(longQuota, 1)
|
longQuota = max(longQuota, 1)
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ internal suspend fun calculateSleepTime(
|
|||||||
mostOldestInLongPeriodGetter: suspend () -> DateTime?
|
mostOldestInLongPeriodGetter: suspend () -> DateTime?
|
||||||
): DateTime? {
|
): DateTime? {
|
||||||
return when {
|
return when {
|
||||||
header.longRemaining < 1 -> mostOldestInLongPeriodGetter() ?.plus(TimeSpan(LONG_TIME_RECALCULATING_MILLIS))
|
header.longRemaining < 1 -> mostOldestInLongPeriodGetter() ?.plus(LONG_TIME_RECALCULATING_MILLIS)
|
||||||
header.shortRemaining < 1 -> mostOldestInShortPeriodGetter() ?.plus(TimeSpan(SHORT_TIME_RECALCULATING_MILLIS))
|
header.shortRemaining < 1 -> mostOldestInShortPeriodGetter() ?.plus(SHORT_TIME_RECALCULATING_MILLIS)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,7 +12,7 @@ import kotlin.coroutines.Continuation
|
|||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
private fun MutableList<DateTime>.clearTooOldTimes(relatedTo: DateTime = DateTime.now()) {
|
private fun MutableList<DateTime>.clearTooOldTimes(relatedTo: DateTime = DateTime.now()) {
|
||||||
val limitValue = relatedTo.minus(TimeSpan(LONG_TIME_RECALCULATING_MILLIS.toDouble()))
|
val limitValue = relatedTo - LONG_TIME_RECALCULATING_MILLIS
|
||||||
|
|
||||||
removeAll {
|
removeAll {
|
||||||
it < limitValue
|
it < limitValue
|
||||||
@ -56,7 +56,7 @@ private data class TimeManagerMostOldestInShortGetter(
|
|||||||
|
|
||||||
val now = DateTime.now()
|
val now = DateTime.now()
|
||||||
|
|
||||||
val limitTime = now.minus(TimeSpan(SHORT_TIME_RECALCULATING_MILLIS.toDouble()))
|
val limitTime = now - SHORT_TIME_RECALCULATING_MILLIS
|
||||||
|
|
||||||
continuation.resumeWith(
|
continuation.resumeWith(
|
||||||
Result.success(
|
Result.success(
|
||||||
|
Loading…
Reference in New Issue
Block a user