Fix SQL connection not getting closed
Fix small bug in js as id field is not being returned anymore
This commit is contained in:
parent
8f9ec25808
commit
334b4be47e
@ -96,10 +96,11 @@ func GetEpisodeTorrents(db *sqlx.DB, imdbID string, season, episode int) ([]polo
|
||||
func UpsertEpisodeTorrent(db *sqlx.DB, torrent *polochon.Torrent, imdbID string, season, episode int) error {
|
||||
// Create the EpisodeTorrent ready to be put in db
|
||||
eDB := NewEpisodeTorrentDB(torrent, imdbID, season, episode)
|
||||
_, err := db.NamedQuery(upsertEpisodeTorrentQuery, eDB)
|
||||
r, err := db.NamedQuery(upsertEpisodeTorrentQuery, eDB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -128,14 +128,10 @@ func GetEpisodes(db *sqlx.DB, pShow *polochon.Show, log *logrus.Entry) error {
|
||||
// UpsertEpisode upserts the episode
|
||||
func UpsertEpisode(db *sqlx.DB, showEpisode *polochon.ShowEpisode) error {
|
||||
e := NewEpisodeFromPolochon(showEpisode)
|
||||
var id string
|
||||
r, err := db.NamedQuery(upsertEpisodeQuery, e)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for r.Next() {
|
||||
r.Scan(&id)
|
||||
}
|
||||
e.ID = id
|
||||
defer r.Close()
|
||||
return nil
|
||||
}
|
||||
|
@ -39,9 +39,10 @@ func Explore(db *sqlx.DB, mtype, msrc, mcat string) (*Media, error) {
|
||||
|
||||
// Upsert adds or updates the Media in the database
|
||||
func (m *Media) Upsert(db *sqlx.DB) error {
|
||||
_, err := db.NamedQuery(upsertExternalMediaQuery, m)
|
||||
r, err := db.NamedQuery(upsertExternalMediaQuery, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
return nil
|
||||
}
|
||||
|
@ -92,10 +92,11 @@ func GetMovieTorrents(db *sqlx.DB, imdbID string) ([]polochon.Torrent, error) {
|
||||
// UpsertMovieTorrent adds or updates MovieTorrent in db
|
||||
func UpsertMovieTorrent(db *sqlx.DB, t *polochon.Torrent, imdbID string) error {
|
||||
mDB := NewMovieTorrentDB(t, imdbID)
|
||||
_, err := db.NamedQuery(upsertMovieTorrentQuery, mDB)
|
||||
r, err := db.NamedQuery(upsertMovieTorrentQuery, mDB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ const (
|
||||
|
||||
isMovieWishlistedQueryByUserID = `
|
||||
SELECT
|
||||
movies.imdb_id
|
||||
COUNT(*)
|
||||
FROM movies INNER JOIN movies_tracked
|
||||
ON
|
||||
movies.imdb_id=movies_tracked.imdb_id
|
||||
@ -89,13 +89,13 @@ func (w *MovieWishlist) IsMovieInWishlist(imdbID string) bool {
|
||||
|
||||
// IsMovieWishlisted returns true if the movie is wishlisted
|
||||
func IsMovieWishlisted(db *sqlx.DB, userID, imdbID string) (bool, error) {
|
||||
var movies = []string{}
|
||||
var count int
|
||||
// Check if the movie is wishlisted by the user
|
||||
err := db.Select(&movies, isMovieWishlistedQueryByUserID, imdbID, userID)
|
||||
err := db.Get(&count, isMovieWishlistedQueryByUserID, imdbID, userID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(movies) > 0 {
|
||||
if count > 0 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@ -117,7 +117,10 @@ func DeleteMovieFromWishlist(db *sqlx.DB, userID, imdbID string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
count, _ := r.RowsAffected()
|
||||
count, err := r.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count != 1 {
|
||||
return fmt.Errorf("Unexpected number of row deleted: %d", count)
|
||||
}
|
||||
|
@ -87,10 +87,11 @@ func FillFromDB(mDB *MovieDB, pMovie *polochon.Movie) {
|
||||
// UpsertMovie upsert a polochon Movie in the database
|
||||
func UpsertMovie(db *sqlx.DB, pMovie *polochon.Movie) error {
|
||||
mDB := NewMovieDB(pMovie)
|
||||
_, err := db.NamedQuery(upsertMovieQuery, mDB)
|
||||
r, err := db.NamedQuery(upsertMovieQuery, mDB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -132,7 +132,10 @@ func DeleteShowFromWishlist(db *sqlx.DB, userID, imdbID string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
count, _ := r.RowsAffected()
|
||||
count, err := r.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count != 1 {
|
||||
return fmt.Errorf("Unexpected number of row deleted: %d", count)
|
||||
}
|
||||
|
@ -43,10 +43,11 @@ type ShowDB struct {
|
||||
func UpsertShow(db *sqlx.DB, s *polochon.Show) error {
|
||||
sDB := NewShowFromPolochon(s)
|
||||
// Upsert the show
|
||||
_, err := db.NamedQuery(upsertShowQuery, sDB)
|
||||
r, err := db.NamedQuery(upsertShowQuery, sDB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
for _, e := range s.Episodes {
|
||||
// Upsert its episodes
|
||||
|
@ -114,10 +114,9 @@ func RefreshShows(env *web.Env) {
|
||||
}
|
||||
}
|
||||
}
|
||||
env.Log.Info("========================================================")
|
||||
// Iterate over the map of shows to refresh them
|
||||
for id := range showMap {
|
||||
show := shows.New(id)
|
||||
show := shows.New(id, env.Config.PublicDir)
|
||||
// Refresh the shows
|
||||
err := show.Refresh(env, env.Config.ShowDetailers)
|
||||
if err != nil {
|
||||
@ -160,7 +159,6 @@ func RefreshMovies(env *web.Env) {
|
||||
}
|
||||
}
|
||||
}
|
||||
env.Log.Info("========================================================")
|
||||
// Iterate over the map of movies to refresh them
|
||||
for id := range movieMap {
|
||||
movie := movies.New(id, nil, nil, false, env.Config.PublicDir)
|
||||
|
@ -170,7 +170,7 @@ func ExploreMovies(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
source := r.FormValue("source")
|
||||
// Default source
|
||||
if source == "" {
|
||||
source = "yts"
|
||||
source = "trakttv"
|
||||
}
|
||||
|
||||
category := r.FormValue("category")
|
||||
@ -210,7 +210,7 @@ func ExploreShows(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
category := r.FormValue("category")
|
||||
// Default category
|
||||
if category == "" {
|
||||
category = "popular"
|
||||
category = "rating"
|
||||
}
|
||||
|
||||
v := auth.GetCurrentUser(r, env.Log)
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/odwrtw/papi"
|
||||
polochon "github.com/odwrtw/polochon/lib"
|
||||
"github.com/odwrtw/polochon/modules/pam"
|
||||
|
||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/auth"
|
||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/backend"
|
||||
@ -42,17 +41,12 @@ func PolochonMoviesHandler(env *web.Env, w http.ResponseWriter, r *http.Request)
|
||||
return err
|
||||
}
|
||||
|
||||
detailer, err := pam.New(&pam.Params{
|
||||
Endpoint: polochonConfig.URL,
|
||||
Token: polochonConfig.Token,
|
||||
})
|
||||
|
||||
// Get details with the polochon Detailer for each polochon.Movies we have
|
||||
for _, m := range movies {
|
||||
// First try from the db
|
||||
first := []polochon.Detailer{env.Backend.Detailer}
|
||||
// Then try from the polochon detailer
|
||||
detailers := []polochon.Detailer{detailer}
|
||||
detailers := env.Config.MovieDetailers
|
||||
err := m.GetAndFetch(env, first, detailers)
|
||||
if err != nil {
|
||||
env.Log.Error(err)
|
||||
|
@ -56,11 +56,12 @@ func (s *Show) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
|
||||
// New returns a new Show with a polochon ShowConfig
|
||||
func New(imdbID string) *Show {
|
||||
func New(imdbID string, publicDir string) *Show {
|
||||
return &Show{
|
||||
Show: &polochon.Show{
|
||||
ImdbID: imdbID,
|
||||
},
|
||||
publicDir: publicDir,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ function updateEpisode(show, fetching, data = null) {
|
||||
|
||||
let seasonIndex = show.seasons.map((el) => el.season).indexOf(data.season.toString());
|
||||
let episodeIndex = show.seasons[seasonIndex].episodes.map((el) => el.episode).indexOf(data.episode);
|
||||
if ('id' in data) {
|
||||
if ('imdb_id' in data) {
|
||||
show.seasons[seasonIndex].episodes[episodeIndex] = data;
|
||||
}
|
||||
show.seasons[seasonIndex].episodes[episodeIndex].fetching = fetching;
|
||||
|
Loading…
x
Reference in New Issue
Block a user