Performance: Querying with filter and filter_by
MEDIUM IMPACT
This affects how quickly the database returns filtered data and how much processing the server does before sending results.
User.query.filter(User.name.like('john%')).all()
User.query.filter(User.name.like('%john%')).all()
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| filter with leading wildcard | N/A | N/A | Delays initial paint due to slow data | [X] Bad |
| filter with indexed prefix | N/A | N/A | Faster data arrival improves paint | [OK] Good |
| filter for equality | N/A | N/A | Slightly slower server processing | [!] OK |
| filter_by for equality | N/A | N/A | Optimized server processing | [OK] Good |