Active Entries
- 1: Surge Pricing for Grocery Stores is a Disaster Only Psychopath MBAs Could Love
- 2: Antarctica Day 7: Swimming In the Antaractic Seas
- 3: Restarted my yoga classes, and I discovered I'm a total wreck
- 4: Antarctica: Getting To the Boat and the Disaster That Awaited
- 5: The Enshittification of All That Lives
- 6: How the green energy discourse resembles queer theory
- 7: Tori's Sake & Grill (restaurant, review)
- 8: I'm Not Always Sure I Trust My ADHD Diagonosis
- 9: You can't call it "Moral Injury" when your "morals" are monstrous
- 10: Ebay vs Newmark: You're all just cogs. Accept it. There is no joy in it, but you have no choice.
Style Credit
- Base style: ColorSide by
- Theme: NNWM 2010 Fresh by
Expand Cut Tags
No cut tags
no subject
Date: 2010-07-14 08:54 am (UTC)my_query = \
models.Foo.objects.filter(field1=val1) \
.exclude(field2=val2, field3=val3) \
.extra(where='func(field4, %s) < 0',
params=[val4])
you're actually creating (and garbage collecting) two QuerySets that you don't care about, before you create the one that you do care about. Django doesn't know that the intermediate ones are useless, so it has no choice but to flesh them out fully enough so that they could be evaluated if necessary. One of the "fleshing out" things it does is to call copy.deepcopy() on the data it inherited from its parent. For instance, in the example above, when it created the second, it would call copy.deepcopy() on val1. When it created the third, it would call copy.deepcopy() on val1, val2, and val3.
We profiled one particularly database-heavy piece of our code and found that it was spending 30% of its time in copy.deepcopy(), because of this!
Creating Q objects and and-ing and or-ing them together to reduce the number of times you have to refine a given QuerySet doesn't seem to help, either.