mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added merging for albums
This commit is contained in:
parent
deb96c9ce7
commit
f0bfe8dfa7
@ -757,6 +757,16 @@ def merge_artists(target_id,source_ids):
|
||||
"status":"success"
|
||||
}
|
||||
|
||||
@api.post("merge_albums")
|
||||
@authenticated_function(api=True)
|
||||
@catch_exceptions
|
||||
def merge_artists(target_id,source_ids):
|
||||
"""Internal Use Only"""
|
||||
result = database.merge_albums(target_id,source_ids)
|
||||
return {
|
||||
"status":"success"
|
||||
}
|
||||
|
||||
@api.post("reparse_scrobble")
|
||||
@authenticated_function(api=True)
|
||||
@catch_exceptions
|
||||
|
@ -221,6 +221,17 @@ def merge_tracks(target_id,source_ids):
|
||||
|
||||
return result
|
||||
|
||||
@waitfordb
|
||||
def merge_albums(target_id,source_ids):
|
||||
sources = [sqldb.get_album(id) for id in source_ids]
|
||||
target = sqldb.get_album(target_id)
|
||||
log(f"Merging {sources} into {target}")
|
||||
result = sqldb.merge_albums(target_id,source_ids)
|
||||
dbcache.invalidate_entity_cache()
|
||||
dbcache.invalidate_caches()
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -647,6 +647,19 @@ def merge_artists(target_id,source_ids,dbconn=None):
|
||||
return True
|
||||
|
||||
|
||||
@connection_provider
|
||||
def merge_albums(target_id,source_ids,dbconn=None):
|
||||
|
||||
op = DB['tracks'].update().where(
|
||||
DB['tracks'].c.album_id.in_(source_ids)
|
||||
).values(
|
||||
album_id=target_id
|
||||
)
|
||||
result = dbconn.execute(op)
|
||||
clean_db(dbconn=dbconn)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
### Functions that get rows according to parameters
|
||||
|
||||
@ -1257,8 +1270,14 @@ def clean_db(dbconn=None):
|
||||
"from scrobbles where track_id in (select id from tracks where id not in (select track_id from trackartists))",
|
||||
"from tracks where id not in (select track_id from trackartists)",
|
||||
# albums with no tracks (albumartist entries first)
|
||||
"from albumartists where album_id in (select id from albums where id not in (select album_id from tracks))",
|
||||
"from albums where id not in (select album_id from tracks)"
|
||||
"from albumartists where album_id in (select id from albums where id not in (select album_id from tracks where album_id is not null))",
|
||||
"from albums where id not in (select album_id from tracks where album_id is not null)",
|
||||
# albumartist entries that are missing a reference
|
||||
"from albumartists where album_id not in (select album_id from tracks where album_id is not null)",
|
||||
"from albumartists where artist_id not in (select id from artists)",
|
||||
# trackartist entries that mare missing a reference
|
||||
"from trackartists where track_id not in (select id from tracks)",
|
||||
"from trackartists where artist_id not in (select id from artists)"
|
||||
]
|
||||
|
||||
for d in to_delete:
|
||||
|
Loading…
Reference in New Issue
Block a user