Last active
April 28, 2020 18:25
-
-
Save susmithagudapati/0721eb70d0920da23f58900ce8ce74d0 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) | |
# loading products with only upc column | |
%timeit Product.objects.only('upc') | |
15.4 µs ± 117 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) | |
# more about 'only()' | |
# this only loads upc and ignores earlier calls | |
Product.objects.only("name", "stock").only("upc") | |
# only and defer combined - this loads only upcs column immediately | |
Product.objects.only("name", "upc").defer("name") | |
# loads upc and name immediately as only() replaces any existing set of fields | |
Product.objects.defer("name").only("upc", "name") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment