diff --git a/hive/db/db_state.py b/hive/db/db_state.py index 76ba73754fb3ea708baec73848321c2aac7f0c9f..258fb23e675ffd010f6b6f51bd1352fc911bdacc 100644 --- a/hive/db/db_state.py +++ b/hive/db/db_state.py @@ -250,6 +250,13 @@ class DbState: force_index_rebuild = True massive_sync_preconditions = True + def vacuum_hive_posts(): + if massive_sync_preconditions: + 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) + #is_pre_process, drop, create cls.processing_indexes( False, force_index_rebuild, True ) @@ -276,10 +283,7 @@ class DbState: time_end = perf_counter() 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) + vacuum_hive_posts() time_start = perf_counter() # Update root_id all root posts @@ -290,10 +294,7 @@ class DbState: 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) + vacuum_hive_posts() time_start = perf_counter() @@ -313,14 +314,10 @@ class DbState: time_end = perf_counter() 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) + vacuum_hive_posts() time_start = perf_counter() - sql = """ SELECT update_feed_cache({}, {}); """.format(last_imported_block, current_imported_block) @@ -362,7 +359,8 @@ 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 + + vacuum_hive_posts() time_start = perf_counter() sql = """ @@ -393,10 +391,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) + 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