Re: Prefetch() with through models

2015-09-17 Thread Erik Cederstrand
> Den 16/09/2015 kl. 19.08 skrev Simon Charette : > > If you want to use this approach I'm afraid you'll have to do > what prefetch_related does under the hood by yourself. > > e.g. > > from collections import defaultdict > > prefetched = defaultdict(list) > subjects =

Re: Prefetch() with through models

2015-09-17 Thread Erik Cederstrand
> Den 17/09/2015 kl. 09.22 skrev Javier Guerra Giraldez : > > On Thu, Sep 17, 2015 at 2:07 AM, Erik Cederstrand > wrote: >>> Den 16/09/2015 kl. 16.45 skrev Mike Dewhirst : >>> >>> On 16/09/2015 9:53 AM, Erik Cederstrand

Re: Prefetch() with through models

2015-09-17 Thread Javier Guerra Giraldez
On Thu, Sep 17, 2015 at 2:07 AM, Erik Cederstrand wrote: >> Den 16/09/2015 kl. 16.45 skrev Mike Dewhirst : >> >> On 16/09/2015 9:53 AM, Erik Cederstrand wrote: >>> issues because the prefetch query does something along the lines of >>> "SELECT ...

Re: Prefetch() with through models

2015-09-17 Thread Erik Cederstrand
> Den 16/09/2015 kl. 16.45 skrev Mike Dewhirst : > > On 16/09/2015 9:53 AM, Erik Cederstrand wrote: >> Hi folks, >> >> I'm working on a school timetable app. I want to fetch hundreds of >> thousands of Lesson instances with prefetched m2m relations (e.g. >> subjects). My

Re: Prefetch() with through models

2015-09-16 Thread Mike Dewhirst
On 16/09/2015 9:53 AM, Erik Cederstrand wrote: Hi folks, I'm working on a school timetable app. I want to fetch hundreds of thousands of Lesson instances with prefetched m2m relations (e.g. subjects). My m2m relations use through models (I'm not sure this actually makes a difference here), and

Re: Prefetch() with through models

2015-09-16 Thread Simon Charette
Hi Erik, I think the prefetch api uses IN [id1, ..., idn] instead of IN (SELECT * ...) because the default isolation level Django runs with is READ COMITTED and using the latter could return different results for the second query. e.g. SELECT id FROM foo WHERE bar = true; -- An other

Prefetch() with through models

2015-09-16 Thread Erik Cederstrand
Hi folks, I'm working on a school timetable app. I want to fetch hundreds of thousands of Lesson instances with prefetched m2m relations (e.g. subjects). My m2m relations use through models (I'm not sure this actually makes a difference here), and I'm running into performance issues because