Add NATURAL_ORDERING opt to disable natsort

With a lot of objects, the sort query took more than 2s to complete,
each time they were listed. Making the concession to disable
natural ordering sort reduces this time to 0.1s, making the listing
views and homepage snappier in our case.
This commit is contained in:
Anthony Ruhier 2018-12-27 23:20:19 +01:00
parent d144d3a584
commit 210ddde630
No known key found for this signature in database
GPG Key ID: 73E9C8657EC59E3A
4 changed files with 21 additions and 3 deletions

View File

@ -207,6 +207,15 @@ The amount of time (in seconds) to wait for NAPALM to connect to a device.
--- ---
## NATURAL_ORDERING
Default: True
Enable or disable the natural sort order when listing objects (see the Wikipedia page for [Natural sort order](https://en.wikipedia.org/wiki/Natural_sort_order)).
However, it is less efficient than the default sort, leading up to a high CPU consumption in database when sorting a lot of objects (a few thousands).
---
## PAGINATE_COUNT ## PAGINATE_COUNT
Default: 50 Default: 50

View File

@ -296,7 +296,8 @@ class Site(ChangeLoggedModel, CustomFieldModel):
to='extras.ImageAttachment' to='extras.ImageAttachment'
) )
objects = NaturalOrderingManager() if settings.NATURAL_ORDERING:
objects = NaturalOrderingManager()
tags = TaggableManager() tags = TaggableManager()
csv_headers = [ csv_headers = [
@ -543,7 +544,8 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
to='extras.ImageAttachment' to='extras.ImageAttachment'
) )
objects = NaturalOrderingManager() if settings.NATURAL_ORDERING:
objects = NaturalOrderingManager()
tags = TaggableManager() tags = TaggableManager()
csv_headers = [ csv_headers = [
@ -1432,7 +1434,8 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
to='extras.ImageAttachment' to='extras.ImageAttachment'
) )
objects = NaturalOrderingManager() if settings.NATURAL_ORDERING:
objects = NaturalOrderingManager()
tags = TaggableManager() tags = TaggableManager()
csv_headers = [ csv_headers = [

View File

@ -118,6 +118,11 @@ NAPALM_TIMEOUT = 30
# be provided as a dictionary. # be provided as a dictionary.
NAPALM_ARGS = {} NAPALM_ARGS = {}
# Enable or disable the natural sort order when listing objects (see https://en.wikipedia.org/wiki/Natural_sort_order
# for details). However, it is less efficient than the default sort, leading up to a high CPU consumption in database
# when sorting a lot of objects (a few thousands).
NATURAL_ORDERING = True
# Determine how many objects to display per page within a list. (Default: 50) # Determine how many objects to display per page within a list. (Default: 50)
PAGINATE_COUNT = 50 PAGINATE_COUNT = 50

View File

@ -63,6 +63,7 @@ NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '')
NAPALM_PASSWORD = getattr(configuration, 'NAPALM_PASSWORD', '') NAPALM_PASSWORD = getattr(configuration, 'NAPALM_PASSWORD', '')
NAPALM_TIMEOUT = getattr(configuration, 'NAPALM_TIMEOUT', 30) NAPALM_TIMEOUT = getattr(configuration, 'NAPALM_TIMEOUT', 30)
NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {}) NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {})
NATURAL_ORDERING = getattr(configuration, 'NATURAL_ORDERING', True)
PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50) PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50)
PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False) PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False)
REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/') REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/')