From ac7a72be0a5a98f605e425332b8303783c4112a1 Mon Sep 17 00:00:00 2001 From: Robert Kaye Date: Mon, 27 Jun 2016 15:51:26 +0200 Subject: [PATCH] Whoops, don't run the program to delete things by default. Also use table listen, not listens. --- config.py.sample | 2 +- webserver/scheduler.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config.py.sample b/config.py.sample index 96f91bc085..b3d98f93b1 100644 --- a/config.py.sample +++ b/config.py.sample @@ -14,7 +14,7 @@ TEST_SQLALCHEMY_DATABASE_URI = "postgresql://lb_test@/lb_test" # Other postgres configuration options # Oldest listens which can be stored in the database, in days. -MAX_POSTGRES_LISTEN_HISTORY = "90" +MAX_POSTGRES_LISTEN_HISTORY = "-1" # Log Postgres queries if they execeed this time, in milliseconds. PG_QUERY_TIMEOUT = "3000" # Disable synchronous_commit to OFF for Postgres. Default: False diff --git a/webserver/scheduler.py b/webserver/scheduler.py index 86d03aca3c..349e6b43ed 100644 --- a/webserver/scheduler.py +++ b/webserver/scheduler.py @@ -32,6 +32,11 @@ def _clean_postgres(self, max_days=90): """ Clean all the listens that are older than a set no of days Default: 90 days """ + + # If max days is set to a negative number, don't throw anything out + if max_days < 0: + return + seconds = max_days*24*3600 engine = create_engine(self.conf['SQLALCHEMY_DATABASE_URI'], poolclass=NullPool) connection = engine.connect() @@ -49,9 +54,9 @@ def _clean_postgres(self, max_days=90): # """ query = """ - DELETE FROM listens + DELETE FROM listen WHERE id in ( - SELECT id FROM listens + SELECT id FROM listen JOIN ( SELECT user_id, extract(epoch from max(ts)) as max FROM listens