Repository navigation
feat(quotas): Optionally exceed quota once [INGEST-1654] - #1521
Conversation
jjbayer
left a comment
There was a problem hiding this comment.
Some suggestions to improve documentation, other than that, this looks good!
| -- parse the incoming string into boolean, returns `nil` if could not parse which is also considered `false` | ||
| local function parse_boolean(v) |
There was a problem hiding this comment.
Can we agree to a protocol and not do these operations? They run quite often and it's expensive. For example, we could use t as truthy value and consider it falsy otherwise.
There was a problem hiding this comment.
Good idea, we could check for the string "true" instead (assuming that is what the rust redis library converts the argument to).
There was a problem hiding this comment.
I reduced this only to "true" and "false" but it does not really matter, we still have to have comparison to the string to get the boolean from that, either we assign this to the variable or do it in the if, there still will be that additional operation. IMHO having function and variable is much cleaner.
There was a problem hiding this comment.
go lisp-style and use t for faster strcmp results :)
i'm not sure what the overheads are of a function in lua, but it is used only once to assign to a variable (which i agree is clearer to read) so could as well write the if statement right there.
| quotas: &[Quota], | ||
| item_scoping: ItemScoping<'_>, | ||
| quantity: usize, | ||
| over_accept_once: bool, |
There was a problem hiding this comment.
nit: using a boolean makes reading the code calling this function harder to read, could we use an enum instead? An example is available in the processor.rs file in this diff. Example:
enum Overaccept {
Once,
No,
}There was a problem hiding this comment.
I get your point, but you could apply this reasoning to any boolean function arg. I'd rather keep it a bool and rely on IDEs to annotate the arguments you're passing.
There was a problem hiding this comment.
this is totally my doing. and yes, i'd do this to any boolean arg :).
There was a problem hiding this comment.
Agreed with @jjbayer , this is overkill in here. If we had 3 and more values we want to accept that we could use enum for that, right now it's only 1 function with one marker flag.
There was a problem hiding this comment.
one day you too will despise boolean args. but i'm not going to die on this hill today :)
| else | ||
| return nil |
There was a problem hiding this comment.
why does this nil branch exist? it's used directly in a boolean expression which i assume will be treated like false. Might as well simplify to if ... true else false
| -- parse the incoming string into boolean, returns `nil` if could not parse which is also considered `false` | ||
| local function parse_boolean(v) |
There was a problem hiding this comment.
go lisp-style and use t for faster strcmp results :)
i'm not sure what the overheads are of a function in lua, but it is used only once to assign to a variable (which i agree is clearer to read) so could as well write the if statement right there.
| quotas: &[Quota], | ||
| item_scoping: ItemScoping<'_>, | ||
| quantity: usize, | ||
| over_accept_once: bool, |
There was a problem hiding this comment.
one day you too will despise boolean args. but i'm not going to die on this hill today :)
For checks with
quantity=0, we need the quota stored in redis to exceed the rate limit to be executed. For this, it's necessary to accept the first call of the rate limiter that exceeds the limit.#skip-changelog