mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Optimize config queries
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from django.core.paginator import Paginator, Page
|
||||
|
||||
from netbox.config import Config
|
||||
from netbox.config import get_config
|
||||
|
||||
|
||||
class EnhancedPaginator(Paginator):
|
||||
@@ -14,9 +14,9 @@ class EnhancedPaginator(Paginator):
|
||||
try:
|
||||
per_page = int(per_page)
|
||||
if per_page < 1:
|
||||
per_page = Config().PAGINATE_COUNT
|
||||
per_page = get_config().PAGINATE_COUNT
|
||||
except ValueError:
|
||||
per_page = Config().PAGINATE_COUNT
|
||||
per_page = get_config().PAGINATE_COUNT
|
||||
|
||||
# Set orphans count based on page size
|
||||
if orphans is None and per_page <= 50:
|
||||
@@ -66,7 +66,7 @@ def get_paginate_count(request):
|
||||
|
||||
Return the lesser of the calculated value and MAX_PAGE_SIZE.
|
||||
"""
|
||||
config = Config()
|
||||
config = get_config()
|
||||
|
||||
if 'per_page' in request.GET:
|
||||
try:
|
||||
|
@@ -14,7 +14,7 @@ from django.utils.html import strip_tags
|
||||
from django.utils.safestring import mark_safe
|
||||
from markdown import markdown
|
||||
|
||||
from netbox.config import Config
|
||||
from netbox.config import get_config
|
||||
from utilities.forms import get_selected_values, TableConfigForm
|
||||
from utilities.utils import foreground_color
|
||||
|
||||
@@ -45,7 +45,7 @@ def render_markdown(value):
|
||||
value = strip_tags(value)
|
||||
|
||||
# Sanitize Markdown links
|
||||
schemes = '|'.join(Config().ALLOWED_URL_SCHEMES)
|
||||
schemes = '|'.join(get_config().ALLOWED_URL_SCHEMES)
|
||||
pattern = fr'\[(.+)\]\((?!({schemes})).*:(.+)\)'
|
||||
value = re.sub(pattern, '[\\1](\\3)', value, flags=re.IGNORECASE)
|
||||
|
||||
|
@@ -9,7 +9,7 @@ from dcim.models import Region, Site
|
||||
from extras.choices import CustomFieldTypeChoices
|
||||
from extras.models import CustomField
|
||||
from ipam.models import VLAN
|
||||
from netbox.config import Config
|
||||
from netbox.config import get_config
|
||||
from utilities.testing import APITestCase, disable_warnings
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ class APIPaginationTestCase(APITestCase):
|
||||
|
||||
def test_default_page_size(self):
|
||||
response = self.client.get(self.url, format='json', **self.header)
|
||||
page_size = Config().PAGINATE_COUNT
|
||||
page_size = get_config().PAGINATE_COUNT
|
||||
self.assertLess(page_size, 100, "Default page size not sufficient for data set")
|
||||
|
||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||
|
@@ -3,7 +3,7 @@ import re
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import _lazy_re_compile, BaseValidator, URLValidator
|
||||
|
||||
from netbox.config import Config
|
||||
from netbox.config import get_config
|
||||
|
||||
|
||||
class EnhancedURLValidator(URLValidator):
|
||||
@@ -24,7 +24,7 @@ class EnhancedURLValidator(URLValidator):
|
||||
def __init__(self, schemes=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
if schemes is not None:
|
||||
self.schemes = Config().ALLOWED_URL_SCHEMES
|
||||
self.schemes = get_config().ALLOWED_URL_SCHEMES
|
||||
|
||||
|
||||
class ExclusionValidator(BaseValidator):
|
||||
|
Reference in New Issue
Block a user