adding pagination requirement to 'names in namespace' api call, and fixing bug in pagination where it would infinite loop trying to fetch pages above the total number of names

This commit is contained in:
Aaron Blankstein
2017-04-21 14:50:40 -04:00
parent 8f1e1c8413
commit 52afc13bd7
2 changed files with 19 additions and 5 deletions

View File

@@ -651,6 +651,9 @@ def get_all_names(offset=None, count=None, proxy=None):
# error
error_str = 'server replied too much data'
return {'error': error_str}
elif len(page) == 0:
# end-of-table
break
all_names += page
@@ -833,6 +836,9 @@ def get_names_in_namespace(namespace_id, offset=None, count=None, proxy=None):
# error
error_str = 'server replied too much data'
return {'error': error_str}
elif len(page) == 0:
# end-of-table
break
all_names += page

View File

@@ -55,9 +55,6 @@ from types import ModuleType
import keylib
from keylib import *
import virtualchain
from virtualchain.lib.ecdsalib import *
import signal
import json
import config as blockstack_config
@@ -1785,8 +1782,19 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
"""
qs_values = path_info['qs_values']
offset = qs_values.get('offset', None)
count = qs_values.get('count', None)
page = qs_values.get('page', None)
if page is None:
log.error("Page required")
return self._reply_json({'error': 'page= argument required'}, status_code=401)
try:
page = int(page)
except ValueError:
log.error("Invalid page")
return self._reply_json({'error': 'Invalid page= value'}, status_code=401)
offset = page * 100
count = 100
namespace_names = proxy.get_names_in_namespace(namespace_id, offset=offset, count=count)
if json_is_error(namespace_names):