From 51a0f7ddc8401c18d3f7d0c7b29ac2441997ff1b Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Mon, 10 Aug 2020 17:48:26 -0400 Subject: [PATCH] add index for release_time --- lbry/db/queries/search.py | 5 ++++- lbry/db/tables.py | 15 ++++++++++++++- setup.py | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lbry/db/queries/search.py b/lbry/db/queries/search.py index 42c5686c5..98f5098c6 100644 --- a/lbry/db/queries/search.py +++ b/lbry/db/queries/search.py @@ -94,8 +94,11 @@ def select_claims(cols: List = None, for_count=False, **constraints) -> Select: raise NameError(f'{column} is not a valid order_by field') if column == 'name': column = 'claim_name' + nulls_last = '' + if column == 'release_time': + nulls_last = ' NULLs LAST' sql_order_by.append( - f"claim.{column} ASC NULLs LAST" if is_asc else f"claim.{column} DESC NULLs LAST" + f"claim.{column} ASC{nulls_last}" if is_asc else f"claim.{column} DESC{nulls_last}" ) constraints['order_by'] = sql_order_by diff --git a/lbry/db/tables.py b/lbry/db/tables.py index fb694cf6c..2ae6733fd 100644 --- a/lbry/db/tables.py +++ b/lbry/db/tables.py @@ -155,7 +155,6 @@ Claim = Table( Column('activation_height', Integer), Column('expiration_height', Integer), Column('takeover_height', Integer, nullable=True), - Column('sync_height', Integer), # claim dynamic values up-to-date as of this height (eg. staked_amount) Column('is_controlling', Boolean), # short_url: normalized#shortest-unique-claim_id @@ -211,6 +210,8 @@ pg_add_claim_and_tag_constraints_and_indexes = [ "CREATE UNIQUE INDEX claim_txo_hash ON claim (txo_hash);", # used by takeover process to reset winning claims "CREATE INDEX claim_normalized ON claim (normalized);", + # ordering and search by release_time + "CREATE INDEX claim_release_time ON claim (release_time DESC NULLs LAST);", # used to count()/sum() claims signed by channel "CREATE INDEX signed_content ON claim (channel_hash) " "INCLUDE (amount) WHERE is_signature_valid;", @@ -247,3 +248,15 @@ pg_add_support_constraints_and_indexes = [ "CREATE INDEX signed_support ON support (channel_hash) " "INCLUDE (amount) WHERE is_signature_valid;", ] + + +Stake = Table( + 'stake', metadata, + Column('claim_hash', LargeBinary), + Column('height', Integer), + Column('stake_min', BigInteger), + Column('stake_max', BigInteger), + Column('stake_sum', BigInteger), + Column('stake_count', Integer), + Column('stake_unique', Integer), +) diff --git a/setup.py b/setup.py index d7a0358ec..b74003785 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ setup( ], }, install_requires=[ - 'aiohttp==3.5.4', + 'aiohttp==3.6.2', 'aioupnp==0.0.17', 'certifi>=2018.11.29', 'colorama==0.3.7',