Opened 11 years ago

Closed 6 years ago

#22115 closed Bug (duplicate)

Related Querysets from Inlines not getting cached

Reported by: john.parton@… Owned by: nobody
Component: contrib.admin Version: 1.6
Severity: Normal Keywords: admin, inline, queryset, queryset caching
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Here's an overview of my code:

    # models.py
    from django.db import models

    class ExampleParent(models.Model):
       
        def __unicode__(self):
            return u'Example Parent: %s' % self.id

    class ExampleInline(models.Model):
        parent = models.ForeignKey('ExampleParent')
        child = models.ForeignKey('ExampleChild')
       
        def __unicode__(self):
            return u'Example Inline: %s' % self.id
       
    class ExampleChild(models.Model):
       
        def __unicode__(self):
            return u'Example Child: %s' % self.id


    # admin.py
    from django.contrib import admin

    from admin_issue.example_problem.models import (ExampleParent, ExampleInline)

    class ExampleInlineInline(admin.TabularInline):
        model = ExampleInline

    class ExampleParentAdmin(admin.ModelAdmin):
        inlines = [
            ExampleInlineInline
        ]

    admin.site.register(ExampleParent, ExampleParentAdmin)

If you go to the admin details for an ExampleParent instance, a query will be executed to fetch all of ExampleChild for as many ExampleInlines are associated with that ExampleParent. These are exactly identical queries. I would expect each queryset to be cached and for the ORM.

I have a few models in production that produces hundreds (sometimes over a thousand) queries. Most of them are exactly identical queries that could be cached.

I could probably patch my code to work around this, but it seems like the expected default behavior would be to cache these.

I can generate a small project with a sqlite db if necessary.

John P.

Change History (3)

comment:1 by Aymeric Augustin, 11 years ago

Triage Stage: UnreviewedAccepted

This makes sense. However, it might be prohibitively hard to implement.

comment:2 by Tim Graham, 6 years ago

Possible duplicate of #5372.

comment:3 by Simon Charette, 6 years ago

Resolution: duplicate
Status: newclosed

I confirm this is a duplicate of #5372.

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