Last active
April 28, 2020 18:25
-
-
Save susmithagudapati/5c885444146fd977eef08781b64dc701 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# retrieving products with all fields | |
%timeit Product.objects.all() | |
6.08 µs ± 97.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) | |
# fetching products after deferring name and category | |
%timeit Product.objects.defer('name', 'category') | |
14.4 µs ± 103 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) | |
# more about using 'defer()' | |
# defers both name and attributes columns | |
Product.objects.defer("name").filter(stock__gt=5).defer("attributes") | |
# defer also works on related object fields | |
Product.objects.select_related().defer("category__created_by") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment