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:
parent
c647a57983
commit
b41203bac7
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user