Opened 10 years ago

Closed 10 years ago

#3845 closed (fixed)

Add db_index to FlatPages 'url' field

Reported by: jesse.lovelace@… Owned by: Adrian Holovaty
Component: Contrib apps Version: master
Severity: Keywords:
Cc: dev@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Currently the FlatPage model doesn't have an index on 'url', but always uses 'url' for the lookup in contrib.flatpages.views:

f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=settings.SITE_ID)

I'm not sure how this could hurt in any case since if you only had a few flatpages your index would be small and if you had many it would be crucial.

Attachments (1)

flatpages_models.diff (743 bytes) - added by Simon G. <dev@…> 10 years ago.
adds db_index=True to flatpages

Download all attachments as: .zip

Change History (4)

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

Attachment: flatpages_models.diff added

adds db_index=True to flatpages

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

Cc: dev@… added
Has patch: set
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedReady for checkin

Well spotted Jesse! Although, looking at that query - shouldn't the index be on (url, sites_id)?

comment:2 Changed 10 years ago by jesse.lovelace@…

I didn't know you could specify composite keys with django and I don't know enough about how MySQL/Postgre optimize index usage to comment. Thanks for the patch!

comment:3 Changed 10 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [4849]) Fixed #3845 -- Added index to URL attribute of flatpages model.

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