Skip to content

Commit

Permalink
Whoops, don't run the program to delete things by default. Also use t…
Browse files Browse the repository at this point in the history
…able listen, not listens.
  • Loading branch information
mayhem committed Jun 27, 2016
1 parent 457297d commit ac7a72b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions webserver/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit ac7a72b

Please sign in to comment.