Skip to content
Snippets Groups Projects
Commit a78090f4 authored by Marcin's avatar Marcin
Browse files

vaccuming tables during final step after initial sync

Some sql functions called in method _after_initial_sync heavy updates
tables (espacialy hive_posts) and produce dead tuples what slowed down db operations.
This behavior sometimes also introduced problems with autovacuum which
cannot clean up fast after this hughe number of updates
parent 85da819a
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!395vaccum at sync final
......@@ -278,16 +278,24 @@ class DbState:
log.info("[INIT] update_hive_posts_children_count executed in %.4fs", time_end - time_start)
time_start = perf_counter()
DbState.db().query_no_return( "VACUUM ANALYZE hive_posts" )
time_end = perf_counter()
log.info("[INIT] VACUUM ANALYZE hive_posts executed in %.4fs", time_end - time_start)
time_start = perf_counter()
# Update root_id all root posts
sql = """
select update_hive_posts_root_id({}, {})
""".format(last_imported_block, current_imported_block)
row = DbState.db().query_row(sql)
time_end = perf_counter()
log.info("[INIT] update_hive_posts_root_id executed in %.4fs", time_end - time_start)
time_start = perf_counter()
DbState.db().query_no_return( "VACUUM ANALYZE hive_posts" )
time_end = perf_counter()
log.info("[INIT] VACUUM ANALYZE hive_posts executed in %.4fs", time_end - time_start)
time_start = perf_counter()
# Update root_id all root posts
......@@ -307,6 +315,12 @@ class DbState:
log.info("[INIT] update_all_posts_active executed in %.4fs", time_end - time_start)
time_start = perf_counter()
DbState.db().query_no_return( "VACUUM ANALYZE hive_posts" )
time_end = perf_counter()
log.info("[INIT] VACUUM ANALYZE hive_posts executed in %.4fs", time_end - time_start)
time_start = perf_counter()
sql = """
SELECT update_feed_cache({}, {});
......@@ -349,6 +363,7 @@ class DbState:
DbState.db().query_no_return(sql)
time_end = perf_counter()
log.info("[INIT] update_posts_rshares executed in %.4fs", time_end - time_start)
# add here 'vacuum analyze hive_posts' when You want to add below more actions which update hive_posts table
time_start = perf_counter()
sql = """
......@@ -379,6 +394,11 @@ class DbState:
log.info("Recreating FKs")
create_fk(cls.db())
time_start = perf_counter()
DbState.db().query_no_return( "VACUUM ANALYZE" )
time_end = perf_counter()
log.info("[INIT] VACUUM ANALYZE executed in %.4fs", time_end - time_start)
@staticmethod
def status():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment