fix order_by and include_totals

This commit is contained in:
Lex Berezhny 2020-08-10 14:03:12 -04:00
parent 6b9cf5b48c
commit 67c5c192f3
2 changed files with 8 additions and 4 deletions

View file

@ -95,7 +95,7 @@ def select_claims(cols: List = None, for_count=False, **constraints) -> Select:
if column == 'name':
column = 'claim_name'
sql_order_by.append(
f"claim.{column} ASC" if is_asc else f"claim.{column} DESC"
f"claim.{column} ASC NULLs LAST" if is_asc else f"claim.{column} DESC NULLs LAST"
)
constraints['order_by'] = sql_order_by
@ -226,7 +226,7 @@ def protobuf_search_claims(**constraints) -> str:
def search_claims(**constraints) -> Tuple[List[Output], Optional[int], Optional[Censor]]:
total = None
if not constraints.pop('no_totals', False):
if constraints.pop('include_totals', False):
total = search_claim_count(**constraints)
constraints['offset'] = abs(constraints.get('offset', 0))
constraints['limit'] = min(abs(constraints.get('limit', 10)), 50)

View file

@ -1629,7 +1629,11 @@ class API:
# kwargs['signature_valid'] = 0
page_num = abs(pagination['page'] or 1)
page_size = min(abs(pagination['page_size'] or DEFAULT_PAGE_SIZE), 50)
claim_filter_dict.update({'offset': page_size * (page_num - 1), 'limit': page_size})
claim_filter_dict.update({
'offset': page_size * (page_num - 1), 'limit': page_size,
'include_totals': pagination['include_totals'],
'order_by': order_by
})
if protobuf:
return await self.service.protobuf_search_claims(**remove_nulls(claim_filter_dict))
result = await self.service.search_claims(
@ -1641,7 +1645,7 @@ class API:
"page": page_num,
"page_size": page_size
}
if not kwargs.pop('no_totals', False):
if pagination['include_totals']:
d['total_pages'] = int((result.total + (page_size - 1)) / page_size)
d['total_items'] = result.total
return d