Ir al contenido

Early Materialization (ARCH2056)

Esta página aún no está disponible en tu idioma.

Key python.orm.early-materialization · Severity warning · Category orm

Filtering or ordering in memory after materializing the query to a list moves work that belongs in the database into the application. Fetching all rows then discarding them is wasteful.

users = list(User.objects.all())
active = [u for u in users if u.is_active] # filtered in memory
active = User.objects.filter(is_active=True) # filter in the DB

Push filtering, ordering, and aggregation into the database with .filter() / .order_by() before materializing.