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:
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:
>>> 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.