Opened 10 years ago

Closed 4 years ago

#3470 closed New feature (fixed)

related data injection for related managers to reduce number of queries

Reported by: Ronny Pfannschmidt Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

it would be nice, of querysets injected objects where used as query parameters to the result set

example using the polls app from the tutorial

from polls.models import *
from django.db import connection
Poll.objects.get(id=1).choice_set.all()[0].poll

results in 3 queries, since the related manager wont pass the orginal poll object to the instances of the choices

after this code connection.queries is

[
 {'time': '0.000', 
  'sql': 'SELECT "polls_poll"."id","polls_poll"."question","polls_poll"."pub_date" FROM "polls_poll" WHERE ("polls_poll"."id" = 1)'},       
 {'time': '0.000', 
  'sql': 'SELECT "polls_choice"."id","polls_choice"."poll_id","polls_choice"."choice","polls_choice"."votes" FROM "polls_choice" WHERE ("polls_choice"."poll_id" = 1) LIMIT 1 '}, 
 {'time': '0.000', 
  'sql': 'SELECT "polls_poll"."id","polls_poll"."question","polls_poll"."pub_date" FROM "polls_poll" WHERE ("polls_poll"."id" = 1)'}]

the same query twice just cause a python object doesn't get passed

Change History (10)

comment:1 Changed 10 years ago by Simon G. <dev@…>

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Summary: related data injection for related managersrelated data injection for related managers to reduce number of queries
Triage Stage: UnreviewedAccepted

comment:2 Changed 10 years ago by Ronny Pfannschmidt <ronny.pfannschmidt@…>

i just noticed #17
i think they both adress a semilar problem

comment:3 Changed 9 years ago by (removed)

Cc: ferringb@… added

comment:4 Changed 9 years ago by Jacob

Reporter: changed from Ronny Pfannschmidt <ronny.pfannschmidt@…> to Ronny Pfannschmidt

comment:5 Changed 8 years ago by Adrian Holovaty

Component: MetasystemDatabase wrapper

comment:6 Changed 8 years ago by (removed)

Cc: ferringb@… removed

comment:7 Changed 6 years ago by Łukasz Rekucki

Severity: Normal
Type: New feature

comment:8 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:9 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:10 Changed 4 years ago by Aymeric Augustin

Resolution: fixed
Status: newclosed

#18177 was a duplicate and it was fixed.

Note: See TracTickets for help on using tickets.
Back to Top