1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +00:00

References deletion

Should fix #38
This commit is contained in:
spl0k 2016-11-11 17:28:14 +01:00
parent 783e9b5465
commit 1de9e2bf6e
4 changed files with 28 additions and 0 deletions

View File

@ -98,6 +98,7 @@ def delete_playlist():
if res.user_id != request.user.id and not request.user.admin: if res.user_id != request.user.id and not request.user.admin:
return request.error_formatter(50, "You're not allowed to delete a playlist that isn't yours") return request.error_formatter(50, "You're not allowed to delete a playlist that isn't yours")
res.tracks.clear()
store.remove(res) store.remove(res)
store.commit() store.commit()
return request.formatter({}) return request.formatter({})

View File

@ -87,6 +87,10 @@ class FolderManager:
for track in store.find(Track, Track.root_folder_id == folder.id): for track in store.find(Track, Track.root_folder_id == folder.id):
scanner.remove_file(track.path) scanner.remove_file(track.path)
scanner.finish() scanner.finish()
store.find(StarredFolder, StarredFolder.starred_id == uid).remove()
store.find(RatingFolder, RatingFolder.rated_id == uid).remove()
store.remove(folder) store.remove(folder)
store.commit() store.commit()

View File

@ -74,6 +74,17 @@ class UserManager:
if status != UserManager.SUCCESS: if status != UserManager.SUCCESS:
return status return status
store.find(StarredFolder, StarredFolder.user_id == uid).remove()
store.find(StarredArtist, StarredArtist.user_id == uid).remove()
store.find(StarredAlbum, StarredAlbum.user_id == uid).remove()
store.find(StarredTrack, StarredTrack.user_id == uid).remove()
store.find(RatingFolder, RatingFolder.user_id == uid).remove()
store.find(RatingTrack, RatingTrack.user_id == uid).remove()
store.find(ChatMessage, ChatMessage.user_id == uid).remove()
for playlist in store.find(Playlist, Playlist.user_id == uid):
playlist.tracks.clear()
store.remove(playlist)
store.remove(user) store.remove(user)
store.commit() store.commit()

View File

@ -102,12 +102,16 @@ class Scanner:
def finish(self): def finish(self):
for album in [ a for a in self.__albums_to_check if not a.tracks.count() ]: for album in [ a for a in self.__albums_to_check if not a.tracks.count() ]:
self.__store.find(StarredAlbum, StarredAlbum.starred_id == album.id).remove()
self.__artists_to_check.add(album.artist) self.__artists_to_check.add(album.artist)
self.__store.remove(album) self.__store.remove(album)
self.__deleted_albums += 1 self.__deleted_albums += 1
self.__albums_to_check.clear() self.__albums_to_check.clear()
for artist in [ a for a in self.__artists_to_check if not a.albums.count() and not a.tracks.count() ]: for artist in [ a for a in self.__artists_to_check if not a.albums.count() and not a.tracks.count() ]:
self.__store.find(StarredArtist, StarredArtist.starred_id == artist.id).remove()
self.__store.remove(artist) self.__store.remove(artist)
self.__deleted_artists += 1 self.__deleted_artists += 1
self.__artists_to_check.clear() self.__artists_to_check.clear()
@ -118,6 +122,9 @@ class Scanner:
continue continue
if not folder.tracks.count() and not folder.children.count(): if not folder.tracks.count() and not folder.children.count():
self.__store.find(StarredFolder, StarredFolder.starred_id == folder.id).remove()
self.__store.find(RatingFolder, RatingFolder.rated_id == folder.id).remove()
self.__folders_to_check.add(folder.parent) self.__folders_to_check.add(folder.parent)
self.__store.remove(folder) self.__store.remove(folder)
@ -193,6 +200,11 @@ class Scanner:
if not tr: if not tr:
return return
self.__store.find(StarredTrack, StarredTrack.starred_id == tr.id).remove()
self.__store.find(RatingTrack, RatingTrack.rated_id == tr.id).remove()
self.__store.find(PlaylistTrack, PlaylistTrack.track_id == tr.id).remove()
self.__store.find(User, User.last_play_id == tr.id).set(User.last_play_id = None)
self.__folders_to_check.add(tr.folder) self.__folders_to_check.add(tr.folder)
self.__albums_to_check.add(tr.album) self.__albums_to_check.add(tr.album)
self.__artists_to_check.add(tr.artist) self.__artists_to_check.add(tr.artist)