Select Star Over Fetch (ARCH2066)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key python.orm.select-star-over-fetch · Severity info · Category orm
Fetching whole entities or all columns when only a few fields are used downstream needlessly inflates row width and serialization cost. Use a projection.
Incorrect
Section titled “Incorrect”def emails(): return [u.email for u in User.objects.all()] # all columns fetchedCorrect
Section titled “Correct”def emails(): return list(User.objects.values_list("email", flat=True)) # email onlyFetch only the needed fields with a values() / values_list() projection.