When we reinitialize the Throttle with a smaller number of allowed operations within a time period, we should preserve the oldest rather than the newest ones, or we'll most likely be in immediate and unfair violation of the limit.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5504 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Par Winzell
2008-11-05 00:21:17 +00:00
parent 2a6940363d
commit bb670e14a8
+3 -4
View File
@@ -86,10 +86,9 @@ public class Throttle
ArrayUtil.copy(_ops, _oldestOp, ops, oldestOp, _ops.length - _oldestOp);
} else if (operations < _ops.length) {
// copy to a smaller buffer, truncating older operations
oldestOp = (_oldestOp + _ops.length - operations) % _ops.length;
var endCount :int = Math.min(_ops.length - oldestOp, operations);
ArrayUtil.copy(_ops, oldestOp, ops, 0, endCount);
// if we're truncating, copy the first (oldest) stamps into ops[0..]
var endCount :int = Math.min(_ops.length - _oldestOp, operations);
ArrayUtil.copy(_ops, _oldestOp, ops, 0, endCount);
ArrayUtil.copy(_ops, 0, ops, endCount, operations - endCount);
_oldestOp = 0;
}