From 80b9caa53779feaacba445a67b5b72cfacdb3be7 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 18 Oct 2022 15:43:27 -0400 Subject: [PATCH] Define max search results limit --- netbox/netbox/search/backends.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/netbox/search/backends.py b/netbox/netbox/search/backends.py index 435ddba83..995582493 100644 --- a/netbox/netbox/search/backends.py +++ b/netbox/netbox/search/backends.py @@ -15,6 +15,7 @@ from utilities.templatetags.builtins.filters import bettertitle from . import FieldTypes, LookupTypes, get_indexer DEFAULT_LOOKUP_TYPE = LookupTypes.PARTIAL +MAX_RESULTS = 1000 class SearchBackend: @@ -108,7 +109,7 @@ class CachedValueSearchBackend(SearchBackend): partition_by=[F('object_type'), F('object_id')], order_by=[F('weight').asc()], ) - ) + )[:MAX_RESULTS] # Construct a Prefetch to pre-fetch only those related objects for which the # user has permission to view. @@ -123,7 +124,6 @@ class CachedValueSearchBackend(SearchBackend): ) # Omit any results pertaining to an object the user does not have permission to view - # TODO: We'll have to figure out how to handle pagination return [ r for r in results if r.object is not None ]