Added chaching, and significantly improved Menu loading times after first
This commit is contained in:
@@ -17,7 +17,8 @@ type Manga struct {
|
|||||||
Thumbnail *bytes.Buffer
|
Thumbnail *bytes.Buffer
|
||||||
|
|
||||||
// Not in DB
|
// Not in DB
|
||||||
LatestChapter *Chapter
|
LatestChapter *Chapter
|
||||||
|
LastChapterNum int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Chapter struct {
|
type Chapter struct {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"cmp"
|
"cmp"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -23,9 +22,6 @@ func (s *Server) HandleNew(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
url := fmt.Sprintf("/title/%s/%s", title, chapter)
|
url := fmt.Sprintf("/title/%s/%s", title, chapter)
|
||||||
|
|
||||||
s.Mutex.Lock()
|
|
||||||
s.ImageBuffers = make(map[string]*bytes.Buffer)
|
|
||||||
s.Mutex.Unlock()
|
|
||||||
s.CurrSubUrl = url
|
s.CurrSubUrl = url
|
||||||
s.PrevSubUrl = ""
|
s.PrevSubUrl = ""
|
||||||
s.NextSubUrl = ""
|
s.NextSubUrl = ""
|
||||||
@@ -76,23 +72,29 @@ func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
|||||||
|
|
||||||
t1 = time.Now().UnixNano()
|
t1 = time.Now().UnixNano()
|
||||||
// This is very slow
|
// This is very slow
|
||||||
l, err := s.Provider.GetChapterList("/title/" + strconv.Itoa(manga.Id))
|
|
||||||
if err != nil {
|
if manga.LastChapterNum == 0 {
|
||||||
continue
|
l, err := s.Provider.GetChapterList("/title/" + strconv.Itoa(manga.Id))
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
le := len(l)
|
||||||
|
_, c, err := s.Provider.GetTitleAndChapter(l[le-1])
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
chapterNumberStr := strings.Replace(c, "ch_", "", 1)
|
||||||
|
|
||||||
|
i, err := strconv.Atoi(chapterNumberStr)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
manga.LastChapterNum = i
|
||||||
}
|
}
|
||||||
|
|
||||||
le := len(l)
|
|
||||||
_, c, err := s.Provider.GetTitleAndChapter(l[le-1])
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
chapterNumberStr := strings.Replace(c, "ch_", "", 1)
|
|
||||||
|
|
||||||
i, err := strconv.Atoi(chapterNumberStr)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
t2 = time.Now().UnixNano()
|
t2 = time.Now().UnixNano()
|
||||||
|
|
||||||
titNs += t2 - t1
|
titNs += t2 - t1
|
||||||
@@ -101,7 +103,7 @@ func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
|||||||
ID: manga.Id,
|
ID: manga.Id,
|
||||||
Title: title,
|
Title: title,
|
||||||
Number: manga.LatestChapter.Number,
|
Number: manga.LatestChapter.Number,
|
||||||
LastNumber: i,
|
LastNumber: manga.LastChapterNum,
|
||||||
// I Hate this time Format... 15 = hh, 04 = mm, 02 = DD, 01 = MM, 06 == YY
|
// I Hate this time Format... 15 = hh, 04 = mm, 02 = DD, 01 = MM, 06 == YY
|
||||||
LastTime: time.Unix(manga.TimeStampUnix, 0).Format("15:04 (02-01-06)"),
|
LastTime: time.Unix(manga.TimeStampUnix, 0).Format("15:04 (02-01-06)"),
|
||||||
Url: manga.LatestChapter.Url,
|
Url: manga.LatestChapter.Url,
|
||||||
@@ -165,8 +167,6 @@ func (s *Server) HandleExit(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Cleaned out of scope Last")
|
|
||||||
|
|
||||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -189,6 +189,7 @@ func (s *Server) HandleExit(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.Mutex.Unlock()
|
s.Mutex.Unlock()
|
||||||
|
fmt.Println("Cleaned last Manga")
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,8 +160,8 @@ func (s *Server) LoadCurr() {
|
|||||||
func (s *Server) LoadThumbnail(mangaId int) (path string, err error) {
|
func (s *Server) LoadThumbnail(mangaId int) (path string, err error) {
|
||||||
strId := strconv.Itoa(mangaId)
|
strId := strconv.Itoa(mangaId)
|
||||||
|
|
||||||
s.Mutex.Lock()
|
//s.Mutex.Lock()
|
||||||
defer s.Mutex.Unlock()
|
//defer s.Mutex.Unlock()
|
||||||
if s.ImageBuffers[strId] != nil {
|
if s.ImageBuffers[strId] != nil {
|
||||||
return strId, nil
|
return strId, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user