1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Fixed database inconsistencies introduced by overeager maintenance

This commit is contained in:
krateng 2022-04-04 17:51:19 +02:00
parent c647a57983
commit b41203bac7

View File

@ -3,6 +3,7 @@ import json
import unicodedata
import math
from datetime import datetime
from threading import Lock
from ..globalconf import data_dir
from .dbcache import cached_wrapper, cached_wrapper_individual, invalidate_entity_cache
@ -60,6 +61,12 @@ DB['associated_artists'] = sql.Table(
meta.create_all(engine)
# adding a scrobble could consist of multiple write operations that sqlite doesn't
# see as belonging together
SCROBBLE_LOCK = Lock()
# decorator that passes either the provided dbconn, or creates a separate one
# just for this function call
def connection_provider(func):
@ -189,6 +196,8 @@ def add_scrobble(scrobbledict,dbconn=None):
@connection_provider
def add_scrobbles(scrobbleslist,dbconn=None):
with SCROBBLE_LOCK:
ops = [
DB['scrobbles'].insert().values(
**scrobble_dict_to_db(s)
@ -619,6 +628,8 @@ def get_artist(id,dbconn=None):
@runhourly
def clean_db():
with SCROBBLE_LOCK:
with engine.begin() as conn:
#log(f"Database Cleanup...")
@ -658,6 +669,7 @@ def clean_db():
@runmonthly
def renormalize_names():
with SCROBBLE_LOCK:
with engine.begin() as conn:
rows = conn.execute(DB['artists'].select()).all()