further fixes to effective amount

This commit is contained in:
Victor Shyba 2020-09-18 20:16:37 -03:00 committed by Lex Berezhny
parent fdac6416a1
commit 25b63c988f
3 changed files with 6 additions and 3 deletions

View file

@ -53,7 +53,7 @@ SEARCH_INTEGER_PARAMS = {
'height', 'creation_height', 'activation_height', 'expiration_height', 'height', 'creation_height', 'activation_height', 'expiration_height',
'timestamp', 'creation_timestamp', 'duration', 'release_time', 'fee_amount', 'timestamp', 'creation_timestamp', 'duration', 'release_time', 'fee_amount',
'tx_position', 'channel_join', 'reposted', 'tx_position', 'channel_join', 'reposted',
'amount', 'effective_amount', 'support_amount', 'amount', 'staked_amount', 'support_amount',
'trending_group', 'trending_mixed', 'trending_group', 'trending_mixed',
'trending_local', 'trending_global', 'trending_local', 'trending_global',
} }

View file

@ -38,6 +38,9 @@ def compat_layer(**constraints):
for old_key, new_key in replacements.items(): for old_key, new_key in replacements.items():
if old_key in constraints: if old_key in constraints:
constraints[new_key] = constraints.pop(old_key) constraints[new_key] = constraints.pop(old_key)
order_by = constraints.get("order_by", [])
if old_key in order_by:
constraints["order_by"] = [order_key if order_key != old_key else new_key for order_key in order_by]
return constraints return constraints
@ -133,7 +136,7 @@ def select_claims(cols: List = None, for_count=False, **constraints) -> Select:
constraints['offset'] = int(constraints.pop('sequence')) - 1 constraints['offset'] = int(constraints.pop('sequence')) - 1
constraints['limit'] = 1 constraints['limit'] = 1
if 'amount_order' in constraints: if 'amount_order' in constraints:
constraints['order_by'] = 'effective_amount DESC' constraints['order_by'] = 'staked_amount DESC'
constraints['offset'] = int(constraints.pop('amount_order')) - 1 constraints['offset'] = int(constraints.pop('amount_order')) - 1
constraints['limit'] = 1 constraints['limit'] = 1

View file

@ -921,7 +921,7 @@ class TestGeneralBlockchainSync(SyncingBlockchainTestCase):
results = await self.db.search_claims(staked_amount=42000000) results = await self.db.search_claims(staked_amount=42000000)
self.assertEqual(claim.claim_id, results[0].claim_id) self.assertEqual(claim.claim_id, results[0].claim_id)
# compat layer # compat layer
results = await self.db.search_claims(effective_amount=42000000) results = await self.db.search_claims(effective_amount=42000000, amount_order=1, order_by=["effective_amount"])
self.assertEqual(claim.claim_id, results[0].claim_id) self.assertEqual(claim.claim_id, results[0].claim_id)