Favor nano time, because it's monotonic

This commit is contained in:
games647
2020-05-13 22:40:26 +02:00
parent c1dc69845e
commit 477d3df1dd
2 changed files with 3 additions and 3 deletions

View File

@ -70,7 +70,7 @@ public class AuthStorage {
// adding paranoid hides hostname, username, version and so // adding paranoid hides hostname, username, version and so
// could be useful for hiding server details // could be useful for hiding server details
config.addDataSourceProperty("paranoid", "true"); config.addDataSourceProperty("paranoid", true);
// enable MySQL specific optimizations // enable MySQL specific optimizations
// disabled by default - will return the same prepared statement instance // disabled by default - will return the same prepared statement instance

View File

@ -21,8 +21,8 @@ public class RateLimiter {
* @return true if allowed * @return true if allowed
*/ */
public boolean tryAcquire() { public boolean tryAcquire() {
// currentTime millis could be expensive on some systems // current time millis is not monotonic - it can jump back depending on user choice or NTP
long now = System.currentTimeMillis(); long now = System.nanoTime() / 1_000_000;
// after this the request should be expired // after this the request should be expired
long toBeExpired = now - expireTime; long toBeExpired = now - expireTime;