Added regular database cleanup

This commit is contained in:
krateng 2022-02-18 05:31:08 +01:00
parent 7e62ddebf6
commit ef594c2546
2 changed files with 25 additions and 1 deletions

View File

@ -8,6 +8,9 @@ from ..globalconf import data_dir
from .dbcache import cached_wrapper
from doreah.logging import log
from doreah.regular import runhourly
##### DB Technical
@ -555,6 +558,27 @@ def get_artist(id):
##### MAINTENANCE
@runhourly
def clean_db():
with engine.begin() as conn:
result1 = conn.execute(sql.text('''
delete from trackartists where track_id in (select id from tracks where id not in (select track_id from scrobbles))
'''))
result2 = conn.execute(sql.text('''
delete from tracks where id not in (select track_id from scrobbles)
'''))
log(f"Database Cleanup... {result1.rowcount+result2.rowcount} entries removed.")
##### AUX FUNCS

View File

@ -188,7 +188,7 @@ malojaconfig = Configuration(
"charts_display_tiles":(tp.Boolean(), "Display Chart Tiles", False),
"discourage_cpu_heavy_stats":(tp.Boolean(), "Discourage CPU-heavy stats", False, "Prevent visitors from mindlessly clicking on CPU-heavy options. Does not actually disable them for malicious actors!"),
"use_local_images":(tp.Boolean(), "Use Local Images", True),
"local_image_rotate":(tp.Integer(), "Local Image Rotate", 3600),
#"local_image_rotate":(tp.Integer(), "Local Image Rotate", 3600),
"timezone":(tp.Integer(), "UTC Offset", 0),
"time_format":(tp.String(), "Time Format", "%d. %b %Y %I:%M %p")
}