diff --git a/src/internal/movies/movies.go b/src/internal/movies/movies.go index 0af223f..8d69cb8 100644 --- a/src/internal/movies/movies.go +++ b/src/internal/movies/movies.go @@ -209,16 +209,17 @@ func (m *Movie) GetDetails(env *web.Env, user *users.User, force bool) error { switch err { case nil: log.Debug("movie found in database") - if !force { - log.Debug("returning movie from db") - return nil - } case sql.ErrNoRows: log.Debug("movie not found in database") default: // Unexpected error return err } + // If force is not specified, don't go further + if !force { + // Will return ErrNoRows if the movie wasn't found + return err + } // GetDetail err = m.Movie.GetDetails(env.Log) @@ -271,21 +272,20 @@ func (m *Movie) GetTorrents(env *web.Env, force bool) error { switch err { case nil: log.Debug("torrents found in database") - if !force { - log.Debugf("returning %d torrents from db", len(movieTorrents)) - // Add the torrents to the movie - for _, t := range movieTorrents { - m.Torrents = append(m.Torrents, t.Torrent) - } - return nil - } case sql.ErrNoRows: log.Debug("torrent not found in database") - // We'll need to GetTorrents from torrenters default: // Unexpected error return err } + if !force { + log.Debugf("returning %d torrents from db", len(movieTorrents)) + // Add the torrents to the movie + for _, t := range movieTorrents { + m.Torrents = append(m.Torrents, t.Torrent) + } + return nil + } err = m.Movie.GetTorrents(env.Log) if err != nil { diff --git a/src/internal/shows/episodes.go b/src/internal/shows/episodes.go index addbba3..338e368 100644 --- a/src/internal/shows/episodes.go +++ b/src/internal/shows/episodes.go @@ -147,18 +147,19 @@ func (e *Episode) GetTorrents(env *web.Env, force bool) error { log.Debug("torrents found in database") case sql.ErrNoRows: log.Debug("torrent not found in database") - // We'll need to GetTorrents from torrenters default: // Unexpected error return err } + // If force is not specified, don't go further if !force { log.Debugf("returning %d torrents from db", len(episodeTorrents)) // Add the torrents to the episode for _, t := range episodeTorrents { e.Torrents = append(e.Torrents, t.Torrent) } - return nil + // Will return ErrNoRows if the torrent wasn't found + return err } err = e.ShowEpisode.GetTorrents(env.Log) diff --git a/src/internal/shows/handlers.go b/src/internal/shows/handlers.go index 156e92c..9fbb45a 100644 --- a/src/internal/shows/handlers.go +++ b/src/internal/shows/handlers.go @@ -31,7 +31,7 @@ func RefreshDetailsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) return DetailsHandler(env, w, r, true) } -// DetailsHandler handles details of a show +// DetailsHandler handles details of an episode func DetailsHandler(env *web.Env, w http.ResponseWriter, r *http.Request, force bool) error { vars := mux.Vars(r) id := vars["id"] diff --git a/src/internal/shows/shows.go b/src/internal/shows/shows.go index 75c3b36..b3473da 100644 --- a/src/internal/shows/shows.go +++ b/src/internal/shows/shows.go @@ -190,16 +190,17 @@ func (s *Show) GetDetails(env *web.Env, user *users.User, force bool) error { switch err { case nil: log.Debug("show found in database") - if !force { - log.Debug("returning show from db") - return nil - } case sql.ErrNoRows: log.Debug("show not found in database") default: // Unexpected error return err } + // If force is not specified, don't go further + if !force { + // Will return ErrNoRows if the show wasn't found + return err + } // GetDetail err = s.Show.GetDetails(env.Log)