Use generator to build search conditions to reduce iterations

This commit is contained in:
sevdog 2023-07-12 17:39:08 +02:00
parent 1ce85d01b5
commit a7bafb7392
No known key found for this signature in database
GPG Key ID: D939AF7A93A9C178

View File

@ -158,13 +158,13 @@ class SearchFilter(BaseFilterBackend):
] ]
base = queryset base = queryset
conditions = [] # generator which for each term builds the corresponding search
for term in search_smart_split(search_terms): conditions = (
queries = [ reduce(
models.Q(**{orm_lookup: term}) operator.or_,
for orm_lookup in orm_lookups (models.Q(**{orm_lookup: term}) for orm_lookup in orm_lookups)
] ) for term in search_smart_split(search_terms)
conditions.append(reduce(operator.or_, queries)) )
queryset = queryset.filter(reduce(operator.and_, conditions)) queryset = queryset.filter(reduce(operator.and_, conditions))
# Remove duplicates from results, if necessary # Remove duplicates from results, if necessary