Separately count photo results to fix included albums counting.

I'm currently running an experiment where albums are also included in
search results, but they don't cost you any of your limit parameter.
So the len(results) was often bigger than limit and tricking this
paginator into thinking we needed a next page when really we didn't.
This workaround can be undone when I decide how to make the album
results more official.
This commit is contained in:
voussoir 2020-09-11 23:12:23 -07:00
parent cfb48a8d11
commit b0dcc6d3c6

View file

@ -398,11 +398,14 @@ def get_search_core():
warnings = set() warnings = set()
search_results = [] search_results = []
search_results_photo_count = 0
for item in search_generator: for item in search_generator:
if isinstance(item, etiquette.objects.WarningBag): if isinstance(item, etiquette.objects.WarningBag):
warnings.update(item.warnings) warnings.update(item.warnings)
else: continue
search_results.append(item) search_results.append(item)
if isinstance(item, etiquette.objects.Photo):
search_results_photo_count += 1
# TAGS ON THIS PAGE # TAGS ON THIS PAGE
total_tags = set() total_tags = set()
@ -416,7 +419,7 @@ def get_search_core():
original_params = request.args.to_dict() original_params = request.args.to_dict()
original_params['limit'] = limit original_params['limit'] = limit
if limit and len(search_results) >= limit: if limit and search_results_photo_count >= limit:
next_params = original_params.copy() next_params = original_params.copy()
next_params['offset'] = offset + limit next_params['offset'] = offset + limit
next_params = helpers.dict_to_params(next_params) next_params = helpers.dict_to_params(next_params)