From e4f802e5f459e4e8b18df7a808a80859ca24cffa Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Sat, 20 Jul 2019 12:17:26 -0400 Subject: [PATCH] when resolving inside channel break a tie of claims with same effective_amount by using height --- lbry/lbry/wallet/server/db/reader.py | 6 +++--- torba/tests/client_tests/unit/test_database.py | 2 +- torba/torba/client/basedatabase.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lbry/lbry/wallet/server/db/reader.py b/lbry/lbry/wallet/server/db/reader.py index c9ffdbbf0..5671e5841 100644 --- a/lbry/lbry/wallet/server/db/reader.py +++ b/lbry/lbry/wallet/server/db/reader.py @@ -56,7 +56,7 @@ SEARCH_PARAMS = { ORDER_FIELDS = { - 'name', + 'name', 'claim_hash' } | INTEGER_PARAMS @@ -334,7 +334,7 @@ def search(constraints) -> Tuple[List, List, int, int]: constraints['offset'] = abs(constraints.get('offset', 0)) constraints['limit'] = min(abs(constraints.get('limit', 10)), 50) if 'order_by' not in constraints: - constraints['order_by'] = ["height", "^name"] + constraints['order_by'] = ["claim_hash"] txo_rows = _search(**constraints) channel_hashes = set(txo['channel_hash'] for txo in txo_rows if txo['channel_hash']) extra_txo_rows = [] @@ -408,7 +408,7 @@ def resolve_url(raw_url): if channel is not None: if set(query) == {'name'}: # temporarily emulate is_controlling for claims in channel - query['order_by'] = ['effective_amount'] + query['order_by'] = ['effective_amount', '^height'] else: query['order_by'] = ['^channel_join'] query['channel_hash'] = channel['claim_hash'] diff --git a/torba/tests/client_tests/unit/test_database.py b/torba/tests/client_tests/unit/test_database.py index d5d45576d..f5e018aed 100644 --- a/torba/tests/client_tests/unit/test_database.py +++ b/torba/tests/client_tests/unit/test_database.py @@ -182,7 +182,7 @@ class TestQueryBuilder(unittest.TestCase): "b IN (select * from blah where c=3) AND " "(one LIKE 'o' OR two = 2) AND " "a0 = 3 AND a00 = 1 AND a00a = 2 AND a00aa = 4 " - "AND ahash = e9cdefe2acf78890ee80537ae3ef84c4faab7ddad7522ea5083e4d93b9274db9 " + "AND ahash = X'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9' " "ORDER BY b LIMIT 10", ) diff --git a/torba/torba/client/basedatabase.py b/torba/torba/client/basedatabase.py index 9cd3e03f2..f04ce10d0 100644 --- a/torba/torba/client/basedatabase.py +++ b/torba/torba/client/basedatabase.py @@ -196,7 +196,7 @@ def interpolate(sql, values): for k in sorted(values.keys(), reverse=True): value = values[k] if isinstance(value, memoryview): - value = hexlify(bytes(value)[::-1]).decode() + value = f"X'{hexlify(bytes(value)).decode()}'" elif isinstance(value, str): value = f"'{value}'" else: