#5570: Improve performance of generic relations
-----------------------+----------------------------------------------------
Reporter: msaelices | Owner: msaelices
Status: new | Component: Database wrapper
Version: SVN | Keywords: generic relations GenericForeignKey
Stage: Unreviewed | Has_patch: 1
-----------------------+----------------------------------------------------
Every access of an object relates to another object with generic relations
send '''two SQL statements'''. I think it should be cached more
efficiently.
Look at this example model:
{{{
#!python
class Note(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField()
related_object = generic.GenericForeignKey('content_type',
'object_id')
class Project(models.Model):
name = models.CharField(maxlength=50)
}}}
Imagine there are two notes asociated both to one project object (not
necessary the same object).
Now look at this code:
{{{
#!python
>>> from django.db import connection
>>> [ n.related_object for n in Note.objects.all() ]
[<Project: Equipo Yaco Community>, <Project: Equipo Yaco Community>]
>>> connection.queries
[{'sql': u'SELECT
"myapp_note"."id","myapp_note"."content_type_id","myapp_note"."object_id"
FROM "projects_note"',
'time': '0.003'},
{'sql': u'SELECT "django_content_type"."id",... FROM
"django_content_type" WHERE ("django_content_type"."id" = 22)',
'time': '0.002'},
{'sql': u'SELECT "django_content_type"."id",... FROM
"django_content_type" WHERE ("django_content_type"."id" = 22)',
'time': '0.002'},
{'sql': u'SELECT "myapp_project"."id","myapp_project"."name" FROM
"myapp_project" WHERE ("myapp_project"."id" = 1)',
}}}
As you can see, there are two identical SQL sentences (number 2 and 3).
But with the patch uploaded, these two sentences reduces in one.
This can be a good improvement for apps that uses intensively generic
relations. In the best of cases, can reduce 50% of SQL sentences in a loop
of adquiring related objects.
--
Ticket URL: <http://code.djangoproject.com/ticket/5570>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---