Skip to content

Commit

Permalink
fix: Implicit conversion from float to int loses precision
Browse files Browse the repository at this point in the history
  • Loading branch information
yll1024335892 authored and hongweipeng committed Sep 12, 2023
1 parent 26b73d8 commit ca64c65
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/throttle/TokenBucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public function allowRequest(string $key, float $micronow, int $max_requests, in

if ($token_left < 1) {
$tmp = (int) ceil($duration / $max_requests);
$this->wait_seconds = $tmp - ($micronow - $last_time) % $tmp;
$this->wait_seconds = $tmp - intval(($micronow - $last_time)) % $tmp;
return false;
}
$this->cur_requests = $max_requests - $token_left;
$cache->set($key, $micronow, $duration);
$cache->set($assist_key, $token_left - 1, $duration);
return true;
}
}
}

0 comments on commit ca64c65

Please sign in to comment.