Early Materialization (ARCH2056)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
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.
Incorrect
Section titled “Incorrect”users = list(User.objects.all())active = [u for u in users if u.is_active] # filtered in memoryCorrect
Section titled “Correct”active = User.objects.filter(is_active=True) # filter in the DBPush filtering, ordering, and aggregation into the database with .filter() / .order_by() before materializing.