Hi Django devs,

I have a small improvement to suggest for one-to-one fields: Make them cache 
back-references on related objects. That is, assume

    class A(model):
        pass

    class B(model):
        a = OneToOneField(A)

    a1 = A.objects.get(...) # assume a1 has a related B record
    b1 = B.objects.get(...)
    
Today, both (a1.b.a is a1) and (b1.a.b is b1) are false; each of the 
expressions generates two database hits. I propose to fix this.

I've run into the issue while doing some performance-improvement work on a 
large project; in this project, the painful instance of the problem was a 
user-profile model. The developers used the reverse of the 1-to-1 on the 
profile 
model instead of django.contrib.auth.models.User.get_profile(), and they often 
navigated between the user object and the profile object in both ways 
(sometimes even for good reasons), generating redundant database hits.

I wrote tests for the problem, and a fix, in the context of the project; I've 
now ported it to a fix in Django itself. It is a small fix, and I think beyond 
its general value, it will allow removing the special-case-caching from 
User.get_profile().

Do you see a reason why I should not post a ticket?

Thanks,
        Shai.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to