when resolving inside channel break a tie of claims with same effective_amount by using height

This commit is contained in:
Lex Berezhny 2019-07-20 12:17:26 -04:00
parent 16fc2c456f
commit e4f802e5f4
3 changed files with 5 additions and 5 deletions

View file

@ -56,7 +56,7 @@ SEARCH_PARAMS = {
ORDER_FIELDS = { ORDER_FIELDS = {
'name', 'name', 'claim_hash'
} | INTEGER_PARAMS } | INTEGER_PARAMS
@ -334,7 +334,7 @@ def search(constraints) -> Tuple[List, List, int, int]:
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:
constraints['order_by'] = ["height", "^name"] constraints['order_by'] = ["claim_hash"]
txo_rows = _search(**constraints) txo_rows = _search(**constraints)
channel_hashes = set(txo['channel_hash'] for txo in txo_rows if txo['channel_hash']) channel_hashes = set(txo['channel_hash'] for txo in txo_rows if txo['channel_hash'])
extra_txo_rows = [] extra_txo_rows = []
@ -408,7 +408,7 @@ def resolve_url(raw_url):
if channel is not None: if channel is not None:
if set(query) == {'name'}: if set(query) == {'name'}:
# temporarily emulate is_controlling for claims in channel # temporarily emulate is_controlling for claims in channel
query['order_by'] = ['effective_amount'] query['order_by'] = ['effective_amount', '^height']
else: else:
query['order_by'] = ['^channel_join'] query['order_by'] = ['^channel_join']
query['channel_hash'] = channel['claim_hash'] query['channel_hash'] = channel['claim_hash']

View file

@ -182,7 +182,7 @@ class TestQueryBuilder(unittest.TestCase):
"b IN (select * from blah where c=3) AND " "b IN (select * from blah where c=3) AND "
"(one LIKE 'o' OR two = 2) AND " "(one LIKE 'o' OR two = 2) AND "
"a0 = 3 AND a00 = 1 AND a00a = 2 AND a00aa = 4 " "a0 = 3 AND a00 = 1 AND a00a = 2 AND a00aa = 4 "
"AND ahash = e9cdefe2acf78890ee80537ae3ef84c4faab7ddad7522ea5083e4d93b9274db9 " "AND ahash = X'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9' "
"ORDER BY b LIMIT 10", "ORDER BY b LIMIT 10",
) )

View file

@ -196,7 +196,7 @@ def interpolate(sql, values):
for k in sorted(values.keys(), reverse=True): for k in sorted(values.keys(), reverse=True):
value = values[k] value = values[k]
if isinstance(value, memoryview): if isinstance(value, memoryview):
value = hexlify(bytes(value)[::-1]).decode() value = f"X'{hexlify(bytes(value)).decode()}'"
elif isinstance(value, str): elif isinstance(value, str):
value = f"'{value}'" value = f"'{value}'"
else: else: