Commit d8a88da
Optimise status code conditions
The current conditions to match which level of log to use are more expensive that they should be. Instead of building a range object and do a lookup in it, which -in the worst case- can go through 100 of elements, it's 2x faster to compare with the 2 integers of the bound:
```
>>> import timeit
>>> timeit.timeit("x in range(400, 500)", setup="from random import randint;x = randint(100, 1000)")
0.08440266699471977
>>> timeit.timeit("400 <= x < 500", setup="from random import randint;x = randint(100, 1000)")
0.0354189580102684
```
As this middleware runs on every request, and info logs go through the if + elif condition, I think this small optimisation, while not life changing, is nice to have.1 parent bdc448d commit d8a88da
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
0 commit comments