Makes the app without global lock

This commit is contained in:
2016-01-25 13:23:39 +01:00
parent 575655b6a4
commit 624b68616e
2 changed files with 14 additions and 43 deletions

View File

@@ -7,6 +7,7 @@ import (
"path"
"regexp"
"strconv"
"strings"
bleve_http "github.com/blevesearch/bleve/http"
"github.com/gorilla/mux"
@@ -23,9 +24,7 @@ func (a *appData) buildRouter() http.Handler {
router.Handle("/api/search", searchHandler).Methods("POST")
router.Handle("/api/recents", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
a.dbLock <- true
albums, err := a.db.ByPurchaseDate()
<-a.dbLock
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -57,15 +56,14 @@ func (a *appData) buildRouter() http.Handler {
return
}
a.dbLock <- true
album, err := a.db.Get(AlbumID(id))
<-a.dbLock
albumUnsafe, err := a.db.Get(AlbumID(id))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
//sanitize extension of the path from bedetheque.com
album := *albumUnsafe
ext := path.Ext(album.CoverURL)
rxExt.ReplaceAllString(ext, "")
ext = strings.ToLower(rxExt.ReplaceAllString(ext, ""))
album.CoverURL = fmt.Sprintf("/covers/%d%s", album.ID, ext)
enc := json.NewEncoder(w)