From 1eab316a6a5dd38bd6a5f3e1006b32c27e3de584 Mon Sep 17 00:00:00 2001 From: crflynn Date: Mon, 14 May 2018 22:40:25 -0400 Subject: [PATCH] add vacuum analyze step to etl task --- pypistats/tasks/pypi.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pypistats/tasks/pypi.py b/pypistats/tasks/pypi.py index cdc22bf..6c86a61 100644 --- a/pypistats/tasks/pypi.py +++ b/pypistats/tasks/pypi.py @@ -271,6 +271,25 @@ def purge_old_data(env="dev", date=None): return success +def vacuum_analyze(env="dev"): + """Vacuum and analyze the db.""" + connection, cursor = get_connection_cursor(env) + connection.set_isolation_level(0) + + results = {} + start = time.time() + cursor.query("VACUUM") + results["vacuum"] = time.time() - start + + start = time.time() + cursor.query("ANALYZE") + results["analyze"] = time.time() - start + + print(results) + return results + + + def get_query(date): """Get the query to execute against pypistats on bigquery.""" return f""" @@ -373,6 +392,7 @@ def etl(): "recent": update_recent_stats(env, date), "purge": purge_old_data(env, date), } + results["cleanup"] vacuum_analyze(env) return results