Opened 10 years ago

Last modified 2 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 10 years ago.
caching-of-sql-queries.diff (694 bytes) - added by Petr Marhoun <petr.marhoun@…> 10 years ago.
formset_refactor_3.diff (47.2 KB) - added by Brian Rosner 9 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)

Changed 10 years ago by anonymous

comment:2 Changed 10 years ago by Petr Marhoun <petr.marhoun@…>

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.

Changed 10 years ago by Petr Marhoun <petr.marhoun@…>

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

comment:3 Changed 10 years ago by Petr Marhoun <petr.marhoun@…>

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

comment:4 Changed 10 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedReady for checkin

comment:5 Changed 10 years ago by Nicola Larosa

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 Changed 9 years ago by Brian Rosner

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.

Changed 9 years ago by Brian Rosner

Attachment: formset_refactor_3.diff added

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

comment:7 Changed 6 years ago by Gabriel Hurley

Severity: Normal
Type: New feature

comment:8 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:9 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:10 Changed 3 years ago by Collin Anderson

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 Changed 3 years ago by Martín Blech

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

comment:12 Changed 3 years ago by Simon Charette

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

comment:13 Changed 3 years ago by Simon Charette

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 Changed 2 years ago by Collin Anderson

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