Disabled more maintenance nonsense when running tasks

This commit is contained in:
krateng 2023-03-31 14:42:58 +02:00
parent 19de87cb66
commit 55363bf31b
2 changed files with 50 additions and 33 deletions

View File

@ -23,11 +23,13 @@ if malojaconfig['USE_GLOBAL_CACHE']:
@runhourly @runhourly
def maintenance(): def maintenance():
from . import AUX_MODE from . import AUX_MODE
if not AUX_MODE: if AUX_MODE: return
print_stats() print_stats()
trim_cache() trim_cache()
def print_stats(): def print_stats():
from . import AUX_MODE
if AUX_MODE: return
for name,c in (('Cache',cache),('Entity Cache',entitycache)): for name,c in (('Cache',cache),('Entity Cache',entitycache)):
hits, misses = c.get_stats() hits, misses = c.get_stats()
log(f"{name}: Size: {len(c)} | Hits: {hits}/{hits+misses} | Estimated Memory: {human_readable_size(c)}") log(f"{name}: Size: {len(c)} | Hits: {hits}/{hits+misses} | Estimated Memory: {human_readable_size(c)}")
@ -35,6 +37,8 @@ if malojaconfig['USE_GLOBAL_CACHE']:
def cached_wrapper(inner_func): def cached_wrapper(inner_func):
from . import AUX_MODE
if AUX_MODE: return inner_func
def outer_func(*args,**kwargs): def outer_func(*args,**kwargs):
@ -59,6 +63,8 @@ if malojaconfig['USE_GLOBAL_CACHE']:
# we don't want a new cache entry for every single combination, but keep a common # we don't want a new cache entry for every single combination, but keep a common
# cache that's aware of what we're calling # cache that's aware of what we're calling
def cached_wrapper_individual(inner_func): def cached_wrapper_individual(inner_func):
from . import AUX_MODE
if AUX_MODE: return
def outer_func(set_arg,**kwargs): def outer_func(set_arg,**kwargs):
if 'dbconn' in kwargs: if 'dbconn' in kwargs:
@ -83,6 +89,9 @@ if malojaconfig['USE_GLOBAL_CACHE']:
return outer_func return outer_func
def invalidate_caches(scrobbletime=None): def invalidate_caches(scrobbletime=None):
from . import AUX_MODE
if AUX_MODE: return
cleared, kept = 0, 0 cleared, kept = 0, 0
for k in cache.keys(): for k in cache.keys():
# VERY BIG TODO: differentiate between None as in 'unlimited timerange' and None as in 'time doesnt matter here'! # VERY BIG TODO: differentiate between None as in 'unlimited timerange' and None as in 'time doesnt matter here'!
@ -95,10 +104,14 @@ if malojaconfig['USE_GLOBAL_CACHE']:
def invalidate_entity_cache(): def invalidate_entity_cache():
from . import AUX_MODE
if AUX_MODE: return
entitycache.clear() entitycache.clear()
def trim_cache(): def trim_cache():
from . import AUX_MODE
if AUX_MODE: return
ramprct = psutil.virtual_memory().percent ramprct = psutil.virtual_memory().percent
if ramprct > malojaconfig["DB_MAX_MEMORY"]: if ramprct > malojaconfig["DB_MAX_MEMORY"]:
log(f"{ramprct}% RAM usage, clearing cache!") log(f"{ramprct}% RAM usage, clearing cache!")

View File

@ -1360,8 +1360,8 @@ def search_album(searchterm,dbconn=None):
def clean_db(dbconn=None): def clean_db(dbconn=None):
from . import AUX_MODE from . import AUX_MODE
if AUX_MODE: return
if not AUX_MODE:
with SCROBBLE_LOCK: with SCROBBLE_LOCK:
log(f"Database Cleanup...") log(f"Database Cleanup...")
@ -1407,6 +1407,10 @@ def clean_db(dbconn=None):
@runmonthly @runmonthly
def renormalize_names(): def renormalize_names():
from . import AUX_MODE
if AUX_MODE: return
with SCROBBLE_LOCK: with SCROBBLE_LOCK:
with engine.begin() as conn: with engine.begin() as conn:
rows = conn.execute(DB['artists'].select()).all() rows = conn.execute(DB['artists'].select()).all()