add index for release_time

This commit is contained in:
Lex Berezhny 2020-08-10 17:48:26 -04:00
parent 1228700487
commit 51a0f7ddc8
3 changed files with 19 additions and 3 deletions

View file

@ -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') raise NameError(f'{column} is not a valid order_by field')
if column == 'name': if column == 'name':
column = 'claim_name' column = 'claim_name'
nulls_last = ''
if column == 'release_time':
nulls_last = ' NULLs LAST'
sql_order_by.append( 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 constraints['order_by'] = sql_order_by

View file

@ -155,7 +155,6 @@ Claim = Table(
Column('activation_height', Integer), Column('activation_height', Integer),
Column('expiration_height', Integer), Column('expiration_height', Integer),
Column('takeover_height', Integer, nullable=True), 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), Column('is_controlling', Boolean),
# short_url: normalized#shortest-unique-claim_id # 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);", "CREATE UNIQUE INDEX claim_txo_hash ON claim (txo_hash);",
# used by takeover process to reset winning claims # used by takeover process to reset winning claims
"CREATE INDEX claim_normalized ON claim (normalized);", "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 # used to count()/sum() claims signed by channel
"CREATE INDEX signed_content ON claim (channel_hash) " "CREATE INDEX signed_content ON claim (channel_hash) "
"INCLUDE (amount) WHERE is_signature_valid;", "INCLUDE (amount) WHERE is_signature_valid;",
@ -247,3 +248,15 @@ pg_add_support_constraints_and_indexes = [
"CREATE INDEX signed_support ON support (channel_hash) " "CREATE INDEX signed_support ON support (channel_hash) "
"INCLUDE (amount) WHERE is_signature_valid;", "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),
)

View file

@ -37,7 +37,7 @@ setup(
], ],
}, },
install_requires=[ install_requires=[
'aiohttp==3.5.4', 'aiohttp==3.6.2',
'aioupnp==0.0.17', 'aioupnp==0.0.17',
'certifi>=2018.11.29', 'certifi>=2018.11.29',
'colorama==0.3.7', 'colorama==0.3.7',