mirror of
https://github.com/krateng/maloja.git
synced 2025-07-09 03:04:07 -04: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 unicodedata
|
||||||
import math
|
import math
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
from ..globalconf import data_dir
|
from ..globalconf import data_dir
|
||||||
from .dbcache import cached_wrapper, cached_wrapper_individual, invalidate_entity_cache
|
from .dbcache import cached_wrapper, cached_wrapper_individual, invalidate_entity_cache
|
||||||
@ -60,6 +61,12 @@ DB['associated_artists'] = sql.Table(
|
|||||||
meta.create_all(engine)
|
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
|
# decorator that passes either the provided dbconn, or creates a separate one
|
||||||
# just for this function call
|
# just for this function call
|
||||||
def connection_provider(func):
|
def connection_provider(func):
|
||||||
@ -189,6 +196,8 @@ def add_scrobble(scrobbledict,dbconn=None):
|
|||||||
@connection_provider
|
@connection_provider
|
||||||
def add_scrobbles(scrobbleslist,dbconn=None):
|
def add_scrobbles(scrobbleslist,dbconn=None):
|
||||||
|
|
||||||
|
with SCROBBLE_LOCK:
|
||||||
|
|
||||||
ops = [
|
ops = [
|
||||||
DB['scrobbles'].insert().values(
|
DB['scrobbles'].insert().values(
|
||||||
**scrobble_dict_to_db(s)
|
**scrobble_dict_to_db(s)
|
||||||
@ -619,6 +628,8 @@ def get_artist(id,dbconn=None):
|
|||||||
|
|
||||||
@runhourly
|
@runhourly
|
||||||
def clean_db():
|
def clean_db():
|
||||||
|
|
||||||
|
with SCROBBLE_LOCK:
|
||||||
with engine.begin() as conn:
|
with engine.begin() as conn:
|
||||||
#log(f"Database Cleanup...")
|
#log(f"Database Cleanup...")
|
||||||
|
|
||||||
@ -658,6 +669,7 @@ def clean_db():
|
|||||||
|
|
||||||
@runmonthly
|
@runmonthly
|
||||||
def renormalize_names():
|
def renormalize_names():
|
||||||
|
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()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user