fixes for old keys

This commit is contained in:
Victor Shyba 2020-12-11 19:31:39 -03:00 committed by Lex Berezhny
parent b31368a3a7
commit 96b506f9fa
3 changed files with 10 additions and 5 deletions

View file

@ -34,7 +34,12 @@ BASE_SELECT_SUPPORT_COLUMNS = BASE_SELECT_TXO_COLUMNS + [
def compat_layer(**constraints): def compat_layer(**constraints):
# for old sdk, to be removed later # for old sdk, to be removed later
replacements = {"effective_amount": "staked_amount"} replacements = {
"effective_amount": "staked_amount",
"trending_mixed": "trend_mixed",
"trending_group": "trend_group",
"trending_local": "trend_local"
}
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)
@ -150,8 +155,8 @@ def select_claims(cols: List = None, for_count=False, **constraints) -> Select:
column = 'claim_name' column = 'claim_name'
table = "trend" if column.startswith('trend') else "claim" table = "trend" if column.startswith('trend') else "claim"
column = f"{table}.{column}" column = f"{table}.{column}"
if column in ('trend_group', 'trend_mixed', 'release_time'): if column in ('trend.trend_group', 'trend.trend_mixed', 'claim.release_time'):
column = f"COALESCE({column}, {1<<32})" column = f"COALESCE({column}, {-1 * (1<<32)})"
sql_order_by.append( sql_order_by.append(
f"{column} {'ASC' if is_asc else 'DESC'}" f"{column} {'ASC' if is_asc else 'DESC'}"
) )

View file

@ -1603,7 +1603,7 @@ class API:
'include_total': pagination['include_total'], 'include_total': pagination['include_total'],
'order_by': order_by 'order_by': order_by
}) })
_, kwargs = pop_kwargs("no_totals", kwargs) # deprecated, ignoring kwargs.pop("no_totals", None) # deprecated, ignoring
claim_filter_dict.update(kwargs) claim_filter_dict.update(kwargs)
if protobuf: if protobuf:
return await self.service.protobuf_search_claims(**remove_nulls(claim_filter_dict)) return await self.service.protobuf_search_claims(**remove_nulls(claim_filter_dict))

View file

@ -1149,7 +1149,7 @@ class TestGeneralBlockchainSync(SyncingBlockchainTestCase):
claim1 = await self.get_claim(await self.create_claim(name="one")) claim1 = await self.get_claim(await self.create_claim(name="one"))
claim2 = await self.get_claim(await self.create_claim(name="two")) claim2 = await self.get_claim(await self.create_claim(name="two"))
await self.generate(1) await self.generate(1)
results = await self.db.search_claims(order_by=["trend_group", "trend_mixed"]) results = await self.db.search_claims(order_by=["trending_group", "trending_mixed"]) # test compat layer
self.assertEqual(0, results.rows[0].meta['trend_mixed']) self.assertEqual(0, results.rows[0].meta['trend_mixed'])
self.assertEqual(0, results.rows[1].meta['trend_mixed']) self.assertEqual(0, results.rows[1].meta['trend_mixed'])
self.assertEqual(0, results.rows[0].meta['trend_group']) self.assertEqual(0, results.rows[0].meta['trend_group'])