divio/django-cms — pull request #1367 by piquadrat (2012-07-30 09:35:40+00:00)
Title: more efficient way to query for the inherited template

* makes only one query, no matter how many levels higher the actual template is (old code made one query per level)
* only queries for the template name and doesn't create full page objects for every level. This turns this:

SELECT "cms_page"."id",
"cms_page"."created_by",
"cms_page"."changed_by",
"cms_page"."parent_id",
"cms_page"."creation_date",
"cms_page"."changed_date",
"cms_page"."publication_date",
"cms_page"."publication_end_date",
"cms_page"."in_navigation",
"cms_page"."soft_root",
"cms_page"."reverse_id",
"cms_page"."navigation_extenders",
"cms_page"."published",
"cms_page"."template",
"cms_page"."site_id",
"cms_page"."moderator_state",
"cms_page"."level",
"cms_page"."lft",
"cms_page"."rght",
"cms_page"."tree_id",
"cms_page"."login_required",
"cms_page"."limit_visibility_in_menu",
"cms_page"."publisher_is_draft",
"cms_page"."publisher_public_id",
"cms_page"."publisher_state"
FROM "cms_page"
WHERE ("cms_page"."lft" <= 1
AND "cms_page"."rght" >= 4
AND "cms_page"."tree_id" = 1)
ORDER BY "cms_page"."lft" DESC

into this:

SELECT "cms_page"."template"
FROM "cms_page"
WHERE ("cms_page"."lft" <= 1
AND "cms_page"."rght" >= 4
AND "cms_page"."tree_id" = 1
AND NOT ("cms_page"."template" = INHERIT))
ORDER BY "cms_page"."lft" DESC LIMIT 1

Also updated the test to pin down the number of queries