Opened 8 years ago

Closed 3 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 8 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from related data injection for related managers to related data injection for related managers to reduce number of queries
  • Triage Stage changed from Unreviewed to Accepted

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

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

comment:3 Changed 8 years ago by (removed)

  • Cc ferringb@… added

comment:4 Changed 8 years ago by jacob

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

comment:5 Changed 7 years ago by adrian

  • Component changed from Metasystem to Database wrapper

comment:6 Changed 7 years ago by (removed)

  • Cc ferringb@… removed

comment:7 Changed 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to New feature

comment:8 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:9 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:10 Changed 3 years ago by aaugustin

  • Resolution set to fixed
  • Status changed from new to closed

#18177 was a duplicate and it was fixed.

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