Skip to content

Commit c04d30b

Browse files
committed
Remove page content lookup from the loop
1 parent d035ecf commit c04d30b

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

cms/cms_menus.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def get_menu_node_for_page(renderer, page, language, fallbacks=None, endpoint=Fa
157157
url=url,
158158
id=page.pk,
159159
attr=attr,
160-
visible=page.get_in_navigation(page_content.language),
160+
visible=page_content.in_navigation,
161161
path=page_url.path or page_url.slug,
162162
language=(page_content.language if page_content.language != language else None),
163163
)
@@ -260,13 +260,11 @@ def get_nodes(self, request):
260260
queryset=translations_qs,
261261
)
262262
prefetch_related_objects(pages, urls_lookup, translations_lookup)
263-
# Build the blank title instances only once
264-
blank_page_content_cache = {language: EmptyPageContent(language=language) for language in languages}
265-
263+
266264
def _page_to_node(page):
267-
# EmptyPageContent is used to prevent the cms from trying
268-
# to find a translation in the database
269-
page.page_content_cache = blank_page_content_cache.copy()
265+
# We're only filling the existing urls and page contents into the cache
266+
# Access the cache directly to not lead to a db hit when accessing
267+
# non-existing languages
270268

271269
for page_url in page.filtered_urls:
272270
page.urls_cache[page_url.language] = page_url
@@ -285,11 +283,9 @@ def _page_to_node(page):
285283

286284
menu_nodes = []
287285

286+
cut_homepage = homepage and not homepage.get_in_navigation(lang)
288287
for page in pages:
289288
if menu_node := _page_to_node(page):
290-
# Only add pages with at least one page content
291-
cut_homepage = homepage and not homepage.get_in_navigation(lang)
292-
293289
if cut_homepage and page.parent_id == homepage.pk:
294290
# When the homepage is hidden from navigation,
295291
# we need to cut all its direct children from it.

0 commit comments

Comments
 (0)