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:
@@ -86,10 +86,9 @@ public class Throttle
|
|||||||
ArrayUtil.copy(_ops, _oldestOp, ops, oldestOp, _ops.length - _oldestOp);
|
ArrayUtil.copy(_ops, _oldestOp, ops, oldestOp, _ops.length - _oldestOp);
|
||||||
|
|
||||||
} else if (operations < _ops.length) {
|
} else if (operations < _ops.length) {
|
||||||
// copy to a smaller buffer, truncating older operations
|
// if we're truncating, copy the first (oldest) stamps into ops[0..]
|
||||||
oldestOp = (_oldestOp + _ops.length - operations) % _ops.length;
|
var endCount :int = Math.min(_ops.length - _oldestOp, operations);
|
||||||
var endCount :int = Math.min(_ops.length - oldestOp, operations);
|
ArrayUtil.copy(_ops, _oldestOp, ops, 0, endCount);
|
||||||
ArrayUtil.copy(_ops, oldestOp, ops, 0, endCount);
|
|
||||||
ArrayUtil.copy(_ops, 0, ops, endCount, operations - endCount);
|
ArrayUtil.copy(_ops, 0, ops, endCount, operations - endCount);
|
||||||
_oldestOp = 0;
|
_oldestOp = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user