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 {
|
func UpsertEpisodeTorrent(db *sqlx.DB, torrent *polochon.Torrent, imdbID string, season, episode int) error {
|
||||||
// Create the EpisodeTorrent ready to be put in db
|
// Create the EpisodeTorrent ready to be put in db
|
||||||
eDB := NewEpisodeTorrentDB(torrent, imdbID, season, episode)
|
eDB := NewEpisodeTorrentDB(torrent, imdbID, season, episode)
|
||||||
_, err := db.NamedQuery(upsertEpisodeTorrentQuery, eDB)
|
r, err := db.NamedQuery(upsertEpisodeTorrentQuery, eDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -128,14 +128,10 @@ func GetEpisodes(db *sqlx.DB, pShow *polochon.Show, log *logrus.Entry) error {
|
|||||||
// UpsertEpisode upserts the episode
|
// UpsertEpisode upserts the episode
|
||||||
func UpsertEpisode(db *sqlx.DB, showEpisode *polochon.ShowEpisode) error {
|
func UpsertEpisode(db *sqlx.DB, showEpisode *polochon.ShowEpisode) error {
|
||||||
e := NewEpisodeFromPolochon(showEpisode)
|
e := NewEpisodeFromPolochon(showEpisode)
|
||||||
var id string
|
|
||||||
r, err := db.NamedQuery(upsertEpisodeQuery, e)
|
r, err := db.NamedQuery(upsertEpisodeQuery, e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for r.Next() {
|
defer r.Close()
|
||||||
r.Scan(&id)
|
|
||||||
}
|
|
||||||
e.ID = id
|
|
||||||
return nil
|
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
|
// Upsert adds or updates the Media in the database
|
||||||
func (m *Media) Upsert(db *sqlx.DB) error {
|
func (m *Media) Upsert(db *sqlx.DB) error {
|
||||||
_, err := db.NamedQuery(upsertExternalMediaQuery, m)
|
r, err := db.NamedQuery(upsertExternalMediaQuery, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer r.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -92,10 +92,11 @@ func GetMovieTorrents(db *sqlx.DB, imdbID string) ([]polochon.Torrent, error) {
|
|||||||
// UpsertMovieTorrent adds or updates MovieTorrent in db
|
// UpsertMovieTorrent adds or updates MovieTorrent in db
|
||||||
func UpsertMovieTorrent(db *sqlx.DB, t *polochon.Torrent, imdbID string) error {
|
func UpsertMovieTorrent(db *sqlx.DB, t *polochon.Torrent, imdbID string) error {
|
||||||
mDB := NewMovieTorrentDB(t, imdbID)
|
mDB := NewMovieTorrentDB(t, imdbID)
|
||||||
_, err := db.NamedQuery(upsertMovieTorrentQuery, mDB)
|
r, err := db.NamedQuery(upsertMovieTorrentQuery, mDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ const (
|
|||||||
|
|
||||||
isMovieWishlistedQueryByUserID = `
|
isMovieWishlistedQueryByUserID = `
|
||||||
SELECT
|
SELECT
|
||||||
movies.imdb_id
|
COUNT(*)
|
||||||
FROM movies INNER JOIN movies_tracked
|
FROM movies INNER JOIN movies_tracked
|
||||||
ON
|
ON
|
||||||
movies.imdb_id=movies_tracked.imdb_id
|
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
|
// IsMovieWishlisted returns true if the movie is wishlisted
|
||||||
func IsMovieWishlisted(db *sqlx.DB, userID, imdbID string) (bool, error) {
|
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
|
// 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 {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if len(movies) > 0 {
|
if count > 0 {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,10 @@ func DeleteMovieFromWishlist(db *sqlx.DB, userID, imdbID string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
count, _ := r.RowsAffected()
|
count, err := r.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if count != 1 {
|
if count != 1 {
|
||||||
return fmt.Errorf("Unexpected number of row deleted: %d", count)
|
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
|
// UpsertMovie upsert a polochon Movie in the database
|
||||||
func UpsertMovie(db *sqlx.DB, pMovie *polochon.Movie) error {
|
func UpsertMovie(db *sqlx.DB, pMovie *polochon.Movie) error {
|
||||||
mDB := NewMovieDB(pMovie)
|
mDB := NewMovieDB(pMovie)
|
||||||
_, err := db.NamedQuery(upsertMovieQuery, mDB)
|
r, err := db.NamedQuery(upsertMovieQuery, mDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,10 @@ func DeleteShowFromWishlist(db *sqlx.DB, userID, imdbID string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
count, _ := r.RowsAffected()
|
count, err := r.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if count != 1 {
|
if count != 1 {
|
||||||
return fmt.Errorf("Unexpected number of row deleted: %d", count)
|
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 {
|
func UpsertShow(db *sqlx.DB, s *polochon.Show) error {
|
||||||
sDB := NewShowFromPolochon(s)
|
sDB := NewShowFromPolochon(s)
|
||||||
// Upsert the show
|
// Upsert the show
|
||||||
_, err := db.NamedQuery(upsertShowQuery, sDB)
|
r, err := db.NamedQuery(upsertShowQuery, sDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
for _, e := range s.Episodes {
|
for _, e := range s.Episodes {
|
||||||
// Upsert its 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
|
// Iterate over the map of shows to refresh them
|
||||||
for id := range showMap {
|
for id := range showMap {
|
||||||
show := shows.New(id)
|
show := shows.New(id, env.Config.PublicDir)
|
||||||
// Refresh the shows
|
// Refresh the shows
|
||||||
err := show.Refresh(env, env.Config.ShowDetailers)
|
err := show.Refresh(env, env.Config.ShowDetailers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -160,7 +159,6 @@ func RefreshMovies(env *web.Env) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
env.Log.Info("========================================================")
|
|
||||||
// Iterate over the map of movies to refresh them
|
// Iterate over the map of movies to refresh them
|
||||||
for id := range movieMap {
|
for id := range movieMap {
|
||||||
movie := movies.New(id, nil, nil, false, env.Config.PublicDir)
|
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")
|
source := r.FormValue("source")
|
||||||
// Default source
|
// Default source
|
||||||
if source == "" {
|
if source == "" {
|
||||||
source = "yts"
|
source = "trakttv"
|
||||||
}
|
}
|
||||||
|
|
||||||
category := r.FormValue("category")
|
category := r.FormValue("category")
|
||||||
@ -210,7 +210,7 @@ func ExploreShows(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
|||||||
category := r.FormValue("category")
|
category := r.FormValue("category")
|
||||||
// Default category
|
// Default category
|
||||||
if category == "" {
|
if category == "" {
|
||||||
category = "popular"
|
category = "rating"
|
||||||
}
|
}
|
||||||
|
|
||||||
v := auth.GetCurrentUser(r, env.Log)
|
v := auth.GetCurrentUser(r, env.Log)
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/odwrtw/papi"
|
"github.com/odwrtw/papi"
|
||||||
polochon "github.com/odwrtw/polochon/lib"
|
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/auth"
|
||||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/backend"
|
"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
|
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
|
// Get details with the polochon Detailer for each polochon.Movies we have
|
||||||
for _, m := range movies {
|
for _, m := range movies {
|
||||||
// First try from the db
|
// First try from the db
|
||||||
first := []polochon.Detailer{env.Backend.Detailer}
|
first := []polochon.Detailer{env.Backend.Detailer}
|
||||||
// Then try from the polochon detailer
|
// Then try from the polochon detailer
|
||||||
detailers := []polochon.Detailer{detailer}
|
detailers := env.Config.MovieDetailers
|
||||||
err := m.GetAndFetch(env, first, detailers)
|
err := m.GetAndFetch(env, first, detailers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
env.Log.Error(err)
|
env.Log.Error(err)
|
||||||
|
@ -56,11 +56,12 @@ func (s *Show) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new Show with a polochon ShowConfig
|
// New returns a new Show with a polochon ShowConfig
|
||||||
func New(imdbID string) *Show {
|
func New(imdbID string, publicDir string) *Show {
|
||||||
return &Show{
|
return &Show{
|
||||||
Show: &polochon.Show{
|
Show: &polochon.Show{
|
||||||
ImdbID: imdbID,
|
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 seasonIndex = show.seasons.map((el) => el.season).indexOf(data.season.toString());
|
||||||
let episodeIndex = show.seasons[seasonIndex].episodes.map((el) => el.episode).indexOf(data.episode);
|
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] = data;
|
||||||
}
|
}
|
||||||
show.seasons[seasonIndex].episodes[episodeIndex].fetching = fetching;
|
show.seasons[seasonIndex].episodes[episodeIndex].fetching = fetching;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user