Skip to content

Commit

Permalink
fix: Mitigate performance hit due to deprecation warnings for v4.1 (#…
Browse files Browse the repository at this point in the history
…7587)

* Dynamic unihan decoder selection based on page language

* Update test

* fix: mitigate performance hit due to deprecation warnings
  • Loading branch information
fsbraun committed Jun 21, 2023
1 parent 1666517 commit 9908d7e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cms/appresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from cms.models.pagemodel import Page
from cms.utils import get_current_site
from cms.utils.i18n import get_language_list
from cms.utils.moderator import use_draft
from cms.utils.moderator import _use_draft

APP_RESOLVERS = []

Expand All @@ -35,7 +35,7 @@ def applications_page_check(request, path=None):
if path.startswith(lang + "/"):
path = path[len(lang + "/"):]

use_public = not use_draft(request)
use_public = not _use_draft(request)

for resolver in APP_RESOLVERS:
try:
Expand Down
6 changes: 3 additions & 3 deletions cms/templatetags/cms_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from cms.plugin_pool import plugin_pool
from cms.toolbar.utils import get_toolbar_from_request
from cms.utils import get_current_site, get_language_from_request, get_site_id
from cms.utils.moderator import use_draft
from cms.utils.moderator import _use_draft
from cms.utils.page import get_page_queryset
from cms.utils.placeholder import validate_placeholder_name
from cms.utils.urlutils import admin_reverse
Expand Down Expand Up @@ -69,7 +69,7 @@ def _get_page_by_untyped_arg(page_lookup, request, site_id):
try:
if 'pk' in page_lookup:
page = Page.objects.select_related('node').get(**page_lookup)
if request and use_draft(request):
if request and _use_draft(request):
if page.publisher_is_draft:
return page
else:
Expand All @@ -80,7 +80,7 @@ def _get_page_by_untyped_arg(page_lookup, request, site_id):
else:
return page
else:
pages = get_page_queryset(site, draft=use_draft(request))
pages = get_page_queryset(site, draft=_use_draft(request))
return pages.select_related('node').get(**page_lookup)
except Page.DoesNotExist:
subject = _('Page not found on %(domain)s') % {'domain': site.domain}
Expand Down
5 changes: 4 additions & 1 deletion cms/utils/moderator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def use_draft(request):
warnings.warn(f"{inspect.stack()[0][3]} is deprecated and will be removed in django CMS 4.1",
DeprecationWarning, stacklevel=2)
return _use_draft(request)

def _use_draft(request):
is_staff = (request.user.is_authenticated and request.user.is_staff)
return is_staff and not request.session.get('cms_preview')

Expand All @@ -15,7 +18,7 @@ def get_model_queryset(model, request=None):
"""
warnings.warn(f"{inspect.stack()[0][3]} is deprecated and will be removed in django CMS 4.1",
DeprecationWarning, stacklevel=2)
if request and use_draft(request):
if request and _use_draft(request):
return model.objects.drafts()
return model.objects.public()

Expand Down
4 changes: 2 additions & 2 deletions cms/utils/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cms.constants import PAGE_USERNAME_MAX_LENGTH
from cms.utils import get_current_site
from cms.utils.conf import get_cms_setting
from cms.utils.moderator import use_draft
from cms.utils.moderator import _use_draft

SUFFIX_REGEX = re.compile(r'^(.*)-(\d+)$')

Expand Down Expand Up @@ -169,7 +169,7 @@ def get_page_from_request(request, use_path=None, clean_path=None):
if clean_path is None:
clean_path = not bool(use_path)

draft = use_draft(request)
draft = _use_draft(request)
preview = 'preview' in request.GET
path = request.path_info if use_path is None else use_path

Expand Down
3 changes: 1 addition & 2 deletions cms/utils/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def assign_plugins(request, placeholders, template=None, lang=None, is_fallback=
return
placeholders = tuple(placeholders)
lang = lang or get_language_from_request(request)
qs = get_cmsplugin_queryset(request)
qs = qs.filter(placeholder__in=placeholders, language=lang)
qs = CMSPlugin.objects.filter(placeholder__in=placeholders, language=lang)
plugins = list(qs.order_by('placeholder', 'path'))
fallbacks = defaultdict(list)
# If no plugin is present in the current placeholder we loop in the fallback languages
Expand Down
2 changes: 1 addition & 1 deletion menus/menu_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from cms.utils import get_current_site
from cms.utils.conf import get_cms_setting
from cms.utils.i18n import get_default_language_for_site, is_language_prefix_patterns_used
from cms.utils.moderator import use_draft
from cms.utils.moderator import _use_draft as use_draft
from menus.base import Menu
from menus.exceptions import NamespaceAlreadyRegistered
from menus.models import CacheKey
Expand Down

0 comments on commit 9908d7e

Please sign in to comment.