forked from LBRYCommunity/lbry-sdk
added --no_totals argument to claim_search
This commit is contained in:
parent
350e610f15
commit
99d21e93f3
4 changed files with 22 additions and 8 deletions
|
@ -1816,6 +1816,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
'publish_time', 'amount', 'effective_amount',
|
'publish_time', 'amount', 'effective_amount',
|
||||||
'support_amount', 'trending_group', 'trending_mixed',
|
'support_amount', 'trending_group', 'trending_mixed',
|
||||||
'trending_local', 'trending_global', 'activation_height'
|
'trending_local', 'trending_global', 'activation_height'
|
||||||
|
--no_totals : (bool) do not calculate the total number of pages and items in result set
|
||||||
|
(significant performance boost)
|
||||||
|
|
||||||
Returns: {Paginated[Output]}
|
Returns: {Paginated[Output]}
|
||||||
"""
|
"""
|
||||||
|
@ -1826,11 +1828,11 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
page_num, page_size = abs(kwargs.pop('page', 1)), min(abs(kwargs.pop('page_size', 10)), 50)
|
page_num, page_size = abs(kwargs.pop('page', 1)), min(abs(kwargs.pop('page_size', 10)), 50)
|
||||||
kwargs.update({'offset': page_size * (page_num-1), 'limit': page_size})
|
kwargs.update({'offset': page_size * (page_num-1), 'limit': page_size})
|
||||||
txos, offset, total = await self.ledger.claim_search(**kwargs)
|
txos, offset, total = await self.ledger.claim_search(**kwargs)
|
||||||
return {
|
result = {"items": txos, "page": page_num, "page_size": page_size}
|
||||||
"items": txos, "page": page_num, "page_size": page_size,
|
if not kwargs.pop('no_totals', False):
|
||||||
"total_pages": int((total + (page_size-1)) / page_size),
|
result['total_pages'] = int((total + (page_size-1)) / page_size)
|
||||||
"total_items": total
|
result['total_items'] = total
|
||||||
}
|
return result
|
||||||
|
|
||||||
CHANNEL_DOC = """
|
CHANNEL_DOC = """
|
||||||
Create, update, abandon and list your channel claims.
|
Create, update, abandon and list your channel claims.
|
||||||
|
|
|
@ -77,7 +77,8 @@ class Outputs:
|
||||||
def to_bytes(cls, txo_rows, extra_txo_rows, offset=0, total=None) -> bytes:
|
def to_bytes(cls, txo_rows, extra_txo_rows, offset=0, total=None) -> bytes:
|
||||||
page = OutputsMessage()
|
page = OutputsMessage()
|
||||||
page.offset = offset
|
page.offset = offset
|
||||||
page.total = total or len(txo_rows)
|
if total is not None:
|
||||||
|
page.total = total
|
||||||
for row in txo_rows:
|
for row in txo_rows:
|
||||||
cls.row_to_message(row, page.txos.add())
|
cls.row_to_message(row, page.txos.add())
|
||||||
for row in extra_txo_rows:
|
for row in extra_txo_rows:
|
||||||
|
|
|
@ -923,7 +923,8 @@ class SQLDB:
|
||||||
'any_tags', 'all_tags', 'not_tags',
|
'any_tags', 'all_tags', 'not_tags',
|
||||||
'any_locations', 'all_locations', 'not_locations',
|
'any_locations', 'all_locations', 'not_locations',
|
||||||
'any_languages', 'all_languages', 'not_languages',
|
'any_languages', 'all_languages', 'not_languages',
|
||||||
'is_controlling', 'limit', 'offset', 'order_by'
|
'is_controlling', 'limit', 'offset', 'order_by',
|
||||||
|
'no_totals',
|
||||||
} | INTEGER_PARAMS
|
} | INTEGER_PARAMS
|
||||||
|
|
||||||
ORDER_FIELDS = {
|
ORDER_FIELDS = {
|
||||||
|
@ -933,7 +934,9 @@ class SQLDB:
|
||||||
def search(self, constraints) -> Tuple[List, List, int, int]:
|
def search(self, constraints) -> Tuple[List, List, int, int]:
|
||||||
assert set(constraints).issubset(self.SEARCH_PARAMS), \
|
assert set(constraints).issubset(self.SEARCH_PARAMS), \
|
||||||
f"Search query contains invalid arguments: {set(constraints).difference(self.SEARCH_PARAMS)}"
|
f"Search query contains invalid arguments: {set(constraints).difference(self.SEARCH_PARAMS)}"
|
||||||
total = self.get_claims_count(**constraints)
|
total = None
|
||||||
|
if not constraints.pop('no_totals', False):
|
||||||
|
total = self.get_claims_count(**constraints)
|
||||||
constraints['offset'] = abs(constraints.get('offset', 0))
|
constraints['offset'] = abs(constraints.get('offset', 0))
|
||||||
constraints['limit'] = min(abs(constraints.get('limit', 10)), 50)
|
constraints['limit'] = min(abs(constraints.get('limit', 10)), 50)
|
||||||
if 'order_by' not in constraints:
|
if 'order_by' not in constraints:
|
||||||
|
|
|
@ -180,6 +180,14 @@ class ClaimSearchCommand(ClaimTestCase):
|
||||||
out_of_bounds = await self.claim_search(page=2, page_size=20, channel='@abc')
|
out_of_bounds = await self.claim_search(page=2, page_size=20, channel='@abc')
|
||||||
self.assertEqual(out_of_bounds, [])
|
self.assertEqual(out_of_bounds, [])
|
||||||
|
|
||||||
|
results = await self.daemon.jsonrpc_claim_search()
|
||||||
|
self.assertEqual(results['total_pages'], 2)
|
||||||
|
self.assertEqual(results['total_items'], 13)
|
||||||
|
|
||||||
|
results = await self.daemon.jsonrpc_claim_search(no_totals=True)
|
||||||
|
self.assertNotIn('total_pages', results)
|
||||||
|
self.assertNotIn('total_items', results)
|
||||||
|
|
||||||
async def test_tag_search(self):
|
async def test_tag_search(self):
|
||||||
claim1 = await self.stream_create('claim1', tags=['aBc'])
|
claim1 = await self.stream_create('claim1', tags=['aBc'])
|
||||||
claim2 = await self.stream_create('claim2', tags=['#abc', 'def'])
|
claim2 = await self.stream_create('claim2', tags=['#abc', 'def'])
|
||||||
|
|
Loading…
Reference in a new issue