Re: Many to Many...so many queries

2010-03-23 Thread TheIvIaxx
yes, this util helped a lot! 300 down to 20 i think. I had a SQL query ready, but then you lose all the ORM goodness. I would think this should be part of the ORM, no? In the SQL, I just had to add another join to the query generated by the select_related() method. The problem is you get dupli

Re: Many to Many...so many queries

2010-03-23 Thread TheIvIaxx
as far as I could tell, select_related did not follow m2m relationships, only FK. On Mar 18, 2:12 am, bruno desthuilliers wrote: > On Mar 18, 8:42 am, koenb wrote: > > > Take a look at something like django-selectreverse [1] for inspiration > > on how to reduce your querycount for M2M relations.

Re: Many to Many...so many queries

2010-03-19 Thread Sam Walters
Yes, this conversation hits the nail on the head. 'select related' only works with forward facing keys. http://code.google.com/p/django-selectreverse/ is a resonably good piece of code to improve performance: using a structure like: class model1(model.Models) 1<* class model2(model.Models

Re: Many to Many...so many queries

2010-03-18 Thread koenb
On 18 mrt, 10:12, bruno desthuilliers wrote: > On Mar 18, 8:42 am, koenb wrote: > > > Take a look at something like django-selectreverse [1] for inspiration > > on how to reduce your querycount for M2M relations. > > > Koen > > > [1]http://code.google.com/p/django-selectreverse/ > > I must be mis

Re: Many to Many...so many queries

2010-03-18 Thread bruno desthuilliers
On Mar 18, 8:42 am, koenb wrote: > Take a look at something like django-selectreverse [1] for inspiration > on how to reduce your querycount for M2M relations. > > Koen > > [1]http://code.google.com/p/django-selectreverse/ > I must be missing the point, but it looks seriously like reinventing t

Re: Many to Many...so many queries

2010-03-18 Thread bruno desthuilliers
On Mar 17, 6:55 pm, TheIvIaxx wrote: > I made a mistake in my model definitions above. And a couple errors in the "view" code snippet too FWIW !-) >  The Term field on > Image is a ManyToMany() not ForeignKey(). > > Anyhow I did look into value_list, however it didn't add much, if any, > perfor

Re: Many to Many...so many queries

2010-03-18 Thread koenb
Take a look at something like django-selectreverse [1] for inspiration on how to reduce your querycount for M2M relations. Koen [1] http://code.google.com/p/django-selectreverse/ On 17 mrt, 18:55, TheIvIaxx wrote: > I made a mistake in my model definitions above.  The Term field on > Image is

Re: Many to Many...so many queries

2010-03-17 Thread TheIvIaxx
I made a mistake in my model definitions above. The Term field on Image is a ManyToMany() not ForeignKey(). Anyhow I did look into value_list, however it didn't add much, if any, performance gain. But the select_related did! That was exactly what I needed. Thanks Bruno for the tip. On Mar 17

Re: Many to Many...so many queries

2010-03-17 Thread bruno desthuilliers
On Mar 17, 4:37 am, TheIvIaxx wrote: > i suppose i could, but that will be a last resort :)  What about > dropping down to raw SQL just to get the IDs: > > SELECT term_id FROM image_term WHERE image_id = %i > > or is that discouraged?  Can it be done with the ORM? You'd have the exact same result

Re: Many to Many...so many queries

2010-03-17 Thread bruno desthuilliers
On Mar 17, 4:24 am, TheIvIaxx wrote: > Hello all, i have a question about a certain query i have.  Here is my > model setup: > > class Term(): >     term = CharField() > > class Image(): >     image = FileField() >     terms = ForeignKey(Term) > > These have been abbreviated for simiplicity, ut yo

Re: Many to Many...so many queries

2010-03-16 Thread Kenneth Gonsalves
On Wednesday 17 Mar 2010 9:07:47 am TheIvIaxx wrote: > i suppose i could, but that will be a last resort :) What about > dropping down to raw SQL just to get the IDs: > > SELECT term_id FROM image_term WHERE image_id = %i > > or is that discouraged? Can it be done with the ORM? > look at 'get

Re: Many to Many...so many queries

2010-03-16 Thread aditya
You can, and I'd be interested to know how much of a speedup that gives. Here's the relevant page on writing raw SQL: http://docs.djangoproject.com/en/dev/topics/db/sql/ If you know SQL (and it looks like you do) it should be familiar territory. The interesting bits are deferring fields, and addin

Re: Many to Many...so many queries

2010-03-16 Thread TheIvIaxx
i suppose i could, but that will be a last resort :) What about dropping down to raw SQL just to get the IDs: SELECT term_id FROM image_term WHERE image_id = %i or is that discouraged? Can it be done with the ORM? On Mar 16, 8:32 pm, aditya wrote: > Is there any way you could reduce the # of

Re: Many to Many...so many queries

2010-03-16 Thread aditya
Is there any way you could reduce the # of images to return? Another thing you could do is cache this info so you don't have to do it multiple times. Aditya On Mar 16, 10:24 pm, TheIvIaxx wrote: > Hello all, i have a question about a certain query i have.  Here is my > model setup: > > class Ter

Many to Many...so many queries

2010-03-16 Thread TheIvIaxx
Hello all, i have a question about a certain query i have. Here is my model setup: class Term(): term = CharField() class Image(): image = FileField() terms = ForeignKey(Term) These have been abbreviated for simiplicity, ut you get the gist of it. Anyhow i have to query for a few h