Skip to content
Snippets Groups Projects

The calls 'list_votes'/'find_votes' work

Merged Mariusz Trela requested to merge mt-find-list-votes3 into develop
All threads resolved!
Files
12
+ 34
10
@@ -46,8 +46,6 @@ class DbState:
log.info("[INIT] Create db schema...")
setup(cls.db())
cls._before_initial_sync()
# perform db migrations
cls._check_migrations()
@@ -114,10 +112,10 @@ class DbState:
'hive_accounts_ix5', # (cached_at, name)
'hive_votes_voter_id_permlink_id_idx',
'hive_votes_permlink_id_voter_id_idx',
'hive_post_tags_tag_id_idx',
'hive_post_tags_tag_id_idx'
'hive_votes_voter_id_post_id_idx',
'hive_votes_post_id_voter_id_idx'
]
to_return = []
@@ -134,12 +132,18 @@ class DbState:
return to_return
@classmethod
def _before_initial_sync(cls):
def before_initial_sync(cls, last_imported_block, hived_head_block):
"""Routine which runs *once* after db setup.
Disables non-critical indexes for faster initial sync, as well
as foreign key constraints."""
to_sync = hived_head_block - last_imported_block
if to_sync < SYNCED_BLOCK_LIMIT:
log.info("[INIT] Skipping pre-initial sync hooks")
return
engine = cls.db().engine()
log.info("[INIT] Begin pre-initial sync hooks")
@@ -159,6 +163,22 @@ class DbState:
log.info("[INIT] Finish pre-initial sync hooks")
@classmethod
def update_work_mem(cls, workmem_value):
row = cls.db().query_row("SHOW work_mem")
current_work_mem = row['work_mem']
sql = """
DO $$
BEGIN
EXECUTE 'ALTER DATABASE '||current_database()||' SET work_mem TO "{}"';
END
$$;
"""
cls.db().query_no_return(sql.format(workmem_value))
return current_work_mem
@classmethod
def _after_initial_sync(cls, current_imported_block, last_imported_block):
"""Routine which runs *once* after initial sync.
@@ -187,6 +207,8 @@ class DbState:
else:
log.info("[INIT] Post-initial sync hooks skipped")
current_work_mem = cls.update_work_mem('2GB')
time_start = perf_counter()
# Update count of all child posts (what was hold during initial sync)
@@ -234,12 +256,14 @@ class DbState:
time_end = perf_counter()
log.info("[INIT] update_all_posts_active executed in %fs", time_end - time_start)
cls.update_work_mem(current_work_mem)
from hive.db.schema import create_fk, set_logged_table_attribute
set_logged_table_attribute(cls.db(), True)
if synced_blocks >= SYNCED_BLOCK_LIMIT:
from hive.db.schema import create_fk, set_logged_table_attribute
set_logged_table_attribute(cls.db(), True)
log.info("Recreating FKs")
create_fk(cls.db())
log.info("Recreating FKs")
create_fk(cls.db())
@staticmethod
def status():
Loading