Opened 17 years ago

Last modified 9 years ago

#5372 new Cleanup/optimization

Cache inline ForeignKey options

Reported by: anonymous Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Normal Keywords: nfa-someday newforms, admin, inlines
Cc: cmawebsite@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description


Attachments (3)

newforms-admin-query-caching.diff (1.0 KB ) - added by anonymous 17 years ago.
caching-of-sql-queries.diff (694 bytes ) - added by Petr Marhoun <petr.marhoun@…> 17 years ago.
formset_refactor_3.diff (47.2 KB ) - added by Brian Rosner 16 years ago.
fixes the real problem. formsets are declarative like forms. 85% done, but attaching to get feedback.

Download all attachments as: .zip

Change History (17)

by anonymous, 17 years ago

comment:2 by Petr Marhoun <petr.marhoun@…>, 17 years ago

I have these models:

from django.db import models

class Category(models.Model):
    name = models.CharField(max_length=255)

class Library(models.Model):
    name = models.CharField(max_length=255)
    
class Book(models.Model):
    name = models.CharField(max_length=255)
    category = models.ForeignKey(Category)
    library = models.ForeignKey(Library)
    

And I register them:

class BookInline(admin.TabularInline):
    model = Book
    extra = 10
    fields = 'name', 'category',

class LibraryOptions(admin.ModelAdmin):
    inlines = BookInline,

admin.site.register(Library, LibraryOptions)

I have ten rows for books in library add form. Each row needs its own sql query to get list of categories. I think that the query should be cached.

It is caching in one request, not between requests. New forms and new formsets are created in each request.

by Petr Marhoun <petr.marhoun@…>, 17 years ago

Attachment: caching-of-sql-queries.diff added

comment:3 by Petr Marhoun <petr.marhoun@…>, 17 years ago

New patch added - the old one doesn't work after [6080].

comment:4 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedReady for checkin

comment:5 by Nicola Larosa, 17 years ago

Needs documentation: set
Needs tests: set
Triage Stage: Ready for checkinDesign decision needed

The discussion about this one did not reach a consensus:

http://groups.google.com/group/django-developers/browse_thread/thread/7aaa8a5297e3c4d5

therefore I'm taking its triage stage back.

comment:6 by Brian Rosner, 16 years ago

Keywords: nfa-someday added
Triage Stage: Design decision neededAccepted

This ticket isn't critical to merge of newforms-admin. Tagging with nfa-someday. This functionality can be accomplished by the user, but I personally feel it needs to be in Django.

by Brian Rosner, 16 years ago

Attachment: formset_refactor_3.diff added

fixes the real problem. formsets are declarative like forms. 85% done, but attaching to get feedback.

comment:7 by Gabriel Hurley, 13 years ago

Severity: Normal
Type: New feature

comment:8 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:9 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:10 by Collin Anderson, 9 years ago

Summary: [newforms-admin] - caching of sql query for inlinesCache inline ForeignKey options
Type: New featureCleanup/optimization

actually, a prefetch_related() call might work just as well.

comment:11 by Martín Blech, 9 years ago

I did some work on this branch: https://github.com/martinblech/django/tree/ticket_5372
Does it make sense?

comment:12 by Simon Charette, 9 years ago

I turned your branch into a PR for easier reviewing and testing.

comment:13 by Simon Charette, 9 years ago

As pointed out on Github the prefetch_related() approach won't work until inline formsets are taught how to deal with it (#18597).

comment:14 by Collin Anderson, 9 years ago

Cc: cmawebsite@… added
Note: See TracTickets for help on using tickets.
Back to Top