Opened 8 years ago

Last modified 4 months 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 8 years ago.
caching-of-sql-queries.diff (694 bytes) - added by Petr Marhoun <petr.marhoun@…> 8 years ago.
formset_refactor_3.diff (47.2 KB) - added by brosner 7 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 8 years ago by anonymous

comment:1 Changed 8 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 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 8 years ago by Petr Marhoun <petr.marhoun@…>

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

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

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

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:5 Changed 8 years ago by tekNico

  • Needs documentation set
  • Needs tests set
  • Triage Stage changed from Ready for checkin to Design 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 7 years ago by brosner

  • Keywords nfa-someday added
  • Triage Stage changed from Design decision needed to Accepted

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 7 years ago by brosner

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

comment:7 Changed 4 years ago by gabrielhurley

  • Severity set to Normal
  • Type set to New feature

comment:8 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:9 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:10 Changed 8 months ago by collinanderson

  • Summary changed from [newforms-admin] - caching of sql query for inlines to Cache inline ForeignKey options
  • Type changed from New feature to Cleanup/optimization

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

comment:11 Changed 6 months ago by martinblech

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

comment:12 Changed 6 months ago by charettes

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

comment:13 Changed 6 months ago by charettes

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 4 months ago by collinanderson

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