Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#28834 closed Cleanup/optimization (fixed)

Fields cache should attempt to follow ancestor links on lookup failures

Reported by: Simon Charette Owned by: Simon Charette
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Given the following models

class Chef(model.Model):
    pass

class Restaurant(models.Model):
    chef = models.ForeignKey(Chef)

class ItalianRestaurant(Restaurant):
    pass

Then given restaurant.chef is cached accessing restaurant.italianrestaurant.chef shouldn't incur an additional query. e.g.

chef = Chef.objects.create()
italian_restaurant = ItalianRestaurant.objects.create(chef=chef)
# A single query with two joins
restaurant = Restaurant.objects.select_related('chef', 'italianrestaurant').get(pk=italian_restaurant.pk)
assert restaurant.chef == chef  # Currently no queries.
assert restaurant.italian_restaurant == italian_restaurant  # Currently no queries.
assert restaurant.italian_restaurant.chef is restaurant.chef  # Currently fails and performs a query.

Change History (5)

comment:1 by Simon Charette, 6 years ago

comment:2 by Tim Graham, 6 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Tim Graham, 6 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Simon Charette <charette.s@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 78c5e7b:

Fixed #28834 -- Followed ancestor links on field cache lookup failure.

Thanks Tim for the review.

comment:5 by Tim Graham <timograham@…>, 6 years ago

In 265506bb:

Refs #28834 -- Moved ancestor field cached value fallback to related fields descriptor.

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