mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 00:36:11 -06:00
Define max search results limit
This commit is contained in:
parent
b216526e01
commit
80b9caa537
@ -15,6 +15,7 @@ from utilities.templatetags.builtins.filters import bettertitle
|
|||||||
from . import FieldTypes, LookupTypes, get_indexer
|
from . import FieldTypes, LookupTypes, get_indexer
|
||||||
|
|
||||||
DEFAULT_LOOKUP_TYPE = LookupTypes.PARTIAL
|
DEFAULT_LOOKUP_TYPE = LookupTypes.PARTIAL
|
||||||
|
MAX_RESULTS = 1000
|
||||||
|
|
||||||
|
|
||||||
class SearchBackend:
|
class SearchBackend:
|
||||||
@ -108,7 +109,7 @@ class CachedValueSearchBackend(SearchBackend):
|
|||||||
partition_by=[F('object_type'), F('object_id')],
|
partition_by=[F('object_type'), F('object_id')],
|
||||||
order_by=[F('weight').asc()],
|
order_by=[F('weight').asc()],
|
||||||
)
|
)
|
||||||
)
|
)[:MAX_RESULTS]
|
||||||
|
|
||||||
# Construct a Prefetch to pre-fetch only those related objects for which the
|
# Construct a Prefetch to pre-fetch only those related objects for which the
|
||||||
# user has permission to view.
|
# 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
|
# 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 [
|
return [
|
||||||
r for r in results if r.object is not None
|
r for r in results if r.object is not None
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user