ORM Lens

DOL001 — Prefer .exists() over .count() > 0

Default severity: info · Applicability: safe · Category: queryset

Detects qs.count() > 0 (and qs.count() >= 1) used as an existence test. .count() makes the database run SELECT COUNT(*), which scans or counts every matching row; .exists() runs SELECT 1 ... LIMIT 1 and stops at the first hit. On large tables the difference is the whole table versus one row. The rewrite is semantically identical, so the QuickFix (“Rewrite to .exists()”) is eligible for auto-apply and “Fix All”.

Bad

if Order.objects.filter(user=user).count() > 0:
    notify(user)

Good

if Order.objects.filter(user=user).exists():
    notify(user)

Suppress

# orm-lens-disable-next-line DOL001

Or per-workspace in .vscode/settings.json: {"djangoOrmLens.rules": {"DOL001": "off"}}.