Makes the app without global lock
This commit is contained in:
12
router.go
12
router.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user