Now actually use Thumbnail that was loaded from db, instead of re downloading it every time. Also save Thumbnail to Manga if it couldnt be saved before
This commit is contained in:
@@ -59,7 +59,7 @@ func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
||||
|
||||
t1 := time.Now().UnixNano()
|
||||
|
||||
thumbnail, err := s.LoadThumbnail(manga.Id)
|
||||
thumbnail, err := s.LoadThumbnail(manga)
|
||||
//TODO: Add default picture instead of not showing Manga at all
|
||||
if err != nil {
|
||||
continue
|
||||
@@ -71,8 +71,9 @@ func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
||||
thumbNs += t2 - t1
|
||||
|
||||
t1 = time.Now().UnixNano()
|
||||
// This is very slow
|
||||
|
||||
// This is very slow
|
||||
// TODO: put this into own Method
|
||||
if manga.LastChapterNum == 0 {
|
||||
l, err := s.Provider.GetChapterList("/title/" + strconv.Itoa(manga.Id))
|
||||
if err != nil {
|
||||
@@ -275,7 +276,7 @@ func (s *Server) HandleImage(w http.ResponseWriter, r *http.Request) {
|
||||
//go:embed favicon.ico
|
||||
var ico []byte
|
||||
|
||||
func (s *Server) HandleFavicon(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *Server) HandleFavicon(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "image/webp")
|
||||
_, err := w.Write(ico)
|
||||
if err != nil {
|
||||
|
||||
@@ -157,16 +157,21 @@ func (s *Server) LoadCurr() {
|
||||
fmt.Println("Loaded current")
|
||||
}
|
||||
|
||||
func (s *Server) LoadThumbnail(mangaId int) (path string, err error) {
|
||||
strId := strconv.Itoa(mangaId)
|
||||
func (s *Server) LoadThumbnail(manga *database.Manga) (path string, err error) {
|
||||
strId := strconv.Itoa(manga.Id)
|
||||
|
||||
//s.Mutex.Lock()
|
||||
//defer s.Mutex.Unlock()
|
||||
s.Mutex.Lock()
|
||||
defer s.Mutex.Unlock()
|
||||
if s.ImageBuffers[strId] != nil {
|
||||
return strId, nil
|
||||
}
|
||||
|
||||
url, err := s.Provider.GetThumbnail(strconv.Itoa(mangaId))
|
||||
if manga.Thumbnail != nil {
|
||||
s.ImageBuffers[strId] = manga.Thumbnail
|
||||
return strId, nil
|
||||
}
|
||||
|
||||
url, err := s.Provider.GetThumbnail(strId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -174,6 +179,7 @@ func (s *Server) LoadThumbnail(mangaId int) (path string, err error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
manga.Thumbnail = ram
|
||||
s.ImageBuffers[strId] = ram
|
||||
return strId, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user