From f7bfa7d153caf297dcde75617eb81a2ae1bb1cee Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Mon, 18 Nov 2024 11:58:20 -0400 Subject: [PATCH] feat: remove unused code --- store/shows.go | 57 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 51 deletions(-) diff --git a/store/shows.go b/store/shows.go index bae6361..246ef8a 100644 --- a/store/shows.go +++ b/store/shows.go @@ -29,11 +29,9 @@ import ( ) type DeleteCounter struct { - Files int64 `json:"files"` - ImportLogs int64 `json:"importLogs"` - PlaylistEntries int64 `json:"playlistEntries"` - Playlists int64 `json:"playlists"` - Shows int64 `json:"shows"` + Files int64 `json:"files"` + ImportLogs int64 `json:"importLogs"` + Shows int64 `json:"shows"` } func (st *Store) getShowPath(showID uint64) string { @@ -100,34 +98,6 @@ func (st *Store) cloneFiles(tx *gorm.DB, showID, from uint64) (fileIDMapping map return } -func (st *Store) clonePlaylists(tx *gorm.DB, showID, from uint64, fileIDMapping map[uint64]uint64) (err error) { - var playlists []Playlist - err = tx.Where("show_id = ?", from).Preload("Entries", func(db *gorm.DB) *gorm.DB { - return db.Order("playlist_entries.line_num asc") - }).Preload("Entries.File").Find(&playlists).Error - if err != nil { - return - } - for _, playlist := range playlists { - playlist.ID = 0 - playlist.ShowID = showID - for idx := range playlist.Entries { - playlist.Entries[idx].ID = 0 - playlist.Entries[idx].PlaylistID = 0 - if playlist.Entries[idx].File != nil { - toFileID, exists := fileIDMapping[playlist.Entries[idx].File.ID] - if exists { - playlist.Entries[idx].File = &File{ID: toFileID, ShowID: showID} - } - } - } - if err = tx.Create(&playlist).Error; err != nil { - return - } - } - return -} - func (st *Store) CloneShow(name, from uint64) (show *Show, err error) { tx := st.db.Begin() defer func() { @@ -167,13 +137,7 @@ func (st *Store) CloneShow(name, from uint64) (show *Show, err error) { tx.Rollback() return } - var fileIDMapping map[uint64]uint64 - if fileIDMapping, err = st.cloneFiles(tx, name, from); err != nil { - tx.Rollback() - _ = os.RemoveAll(st.getShowPath(name)) // dear linter: we are deliberately not handling errors from RemoveAll() - return - } - if err = st.clonePlaylists(tx, name, from, fileIDMapping); err != nil { + if _, err = st.cloneFiles(tx, name, from); err != nil { tx.Rollback() _ = os.RemoveAll(st.getShowPath(name)) // dear linter: we are deliberately not handling errors from RemoveAll() return @@ -198,14 +162,7 @@ func (st *Store) DeleteShow(showID uint64) (err error) { return } - // We have to delete the playlists first because cascading order is not fixed and the - // DBMS might try to delete files before playlists which does not work as long as - // there are likely playlists that reference the files. - if err = tx.Where("show_id = ?", showID).Delete(&Playlist{}).Error; err != nil { - tx.Rollback() - return - } - // Playlists are now gone, deleting the show will cascade to delete the files as well. + // deleting the show will cascade to delete the files as well. if err = tx.Delete(&Show{ID: showID}).Error; err != nil { tx.Rollback() return @@ -244,12 +201,10 @@ func removeDirectories(path string) (err error) { func (st *Store) ResetState() (deleteCounter DeleteCounter, err error) { importLogs := st.db.Exec("DELETE FROM import_logs").RowsAffected - playlistEntries := st.db.Exec("DELETE FROM playlist_entries").RowsAffected - playlists := st.db.Exec("DELETE FROM playlists").RowsAffected files := st.db.Exec("DELETE FROM files").RowsAffected shows := st.db.Exec("DELETE FROM shows").RowsAffected err = removeDirectories(filepath.Join(st.basePath, "*")) - return DeleteCounter{Files: files, ImportLogs: importLogs, PlaylistEntries: playlistEntries, Playlists: playlists, Shows: shows}, err + return DeleteCounter{Files: files, ImportLogs: importLogs, Shows: shows}, err } -- GitLab