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

Added more connection passing

This commit is contained in:
krateng 2022-04-25 22:00:32 +02:00
parent 8845f931df
commit cf04583122

View File

@ -442,7 +442,7 @@ def merge_tracks(target_id,source_ids,dbconn=None):
track_id=target_id
)
result = dbconn.execute(op)
clean_db()
clean_db(dbconn=dbconn)
return True
@ -491,8 +491,8 @@ def merge_artists(target_id,source_ids,dbconn=None):
# result = dbconn.execute(op)
# this could have created duplicate tracks
merge_duplicate_tracks(artist_id=target_id)
clean_db()
merge_duplicate_tracks(artist_id=target_id,dbconn=dbconn)
clean_db(dbconn=dbconn)
return True
@ -871,10 +871,9 @@ def search_track(searchterm,dbconn=None):
##### MAINTENANCE
@runhourly
def clean_db():
@connection_provider
def clean_db(dbconn=None):
with SCROBBLE_LOCK:
with engine.begin() as conn:
log(f"Database Cleanup...")
to_delete = [
@ -889,10 +888,10 @@ def clean_db():
]
for d in to_delete:
selection = conn.execute(sql.text(f"select * {d}"))
selection = dbconn.execute(sql.text(f"select * {d}"))
for row in selection.all():
log(f"Deleting {row}")
deletion = conn.execute(sql.text(f"delete {d}"))
deletion = dbconn.execute(sql.text(f"delete {d}"))
log("Database Cleanup complete!")
@ -923,10 +922,9 @@ def renormalize_names():
rows = conn.execute(DB['artists'].update().where(DB['artists'].c.id == id).values(name_normalized=norm_target))
def merge_duplicate_tracks(artist_id):
with engine.begin() as conn:
rows = conn.execute(
@connection_provider
def merge_duplicate_tracks(artist_id,dbconn=None):
rows = dbconn.execute(
DB['trackartists'].select().where(
DB['trackartists'].c.artist_id == artist_id
)
@ -934,7 +932,7 @@ def merge_duplicate_tracks(artist_id):
affected_tracks = [r.track_id for r in rows]
track_artists = {}
rows = conn.execute(
rows = dbconn.execute(
DB['trackartists'].select().where(
DB['trackartists'].c.track_id.in_(affected_tracks)
)