aboutsummaryrefslogtreecommitdiff
path: root/modules/grils
diff options
context:
space:
mode:
authorJan C <jan@ruken.pw>2016-03-28 12:30:15 (UTC)
committerJan C <jan@ruken.pw>2016-03-28 12:30:15 (UTC)
commite8f2412efe55c969390168e3ce0b41200f780a1e (patch)
tree41a0e692d0ded0113394712f750b730c4f4fa864 /modules/grils
parentc7f28c0032163075bd21f899c37ae992e3eece80 (diff)
cache hinzugefuegt. wird derzeit vom lists und grils modul verwendet. versuch die loadingzeit zu verringern (anscheinend wird im hintergrund auf jeder route der index requested, was ziemlich doof ist).
Diffstat (limited to 'modules/grils')
-rw-r--r--modules/grils/gril.go4
-rw-r--r--modules/grils/grils.go16
2 files changed, 17 insertions, 3 deletions
diff --git a/modules/grils/gril.go b/modules/grils/gril.go
index 7b782b3..f78d31f 100644
--- a/modules/grils/gril.go
+++ b/modules/grils/gril.go
@@ -46,12 +46,12 @@ func ImagePath(id int, prioritizeThumbnail bool) string {
46 // Image Priority 46 // Image Priority
47 // without prioritizeThumbnail: Anilist > ACD (big) > ACD (thumbnail) 47 // without prioritizeThumbnail: Anilist > ACD (big) > ACD (thumbnail)
48 // with prioritizeThumbnail: Anilist > ACD (thumbnail) > ACD (big) 48 // with prioritizeThumbnail: Anilist > ACD (thumbnail) > ACD (big)
49 49
50 anilistPath := fmt.Sprintf("assets/img/gril/%d/%d.jpg", DataSourceAnilist, id) 50 anilistPath := fmt.Sprintf("assets/img/gril/%d/%d.jpg", DataSourceAnilist, id)
51 if _, err := os.Stat(anilistPath); err == nil { 51 if _, err := os.Stat(anilistPath); err == nil {
52 return fmt.Sprintf(anilistPath) 52 return fmt.Sprintf(anilistPath)
53 } 53 }
54 54
55 var big string 55 var big string
56 exts := []string{"png", "jpg", "gif", "jpeg"} 56 exts := []string{"png", "jpg", "gif", "jpeg"}
57 for _, ext := range exts { 57 for _, ext := range exts {
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index fe947bc..791ea5e 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -6,16 +6,22 @@ import (
6 "net/http" 6 "net/http"
7 "regexp" 7 "regexp"
8 "strconv" 8 "strconv"
9 "time"
9 "strings" 10 "strings"
10 "time"
11 11
12 "fagott.pw/charakterin" 12 "fagott.pw/charakterin"
13 "fagott.pw/grilist/frontend" 13 "fagott.pw/grilist/frontend"
14 "fagott.pw/grilist/grilist" 14 "fagott.pw/grilist/grilist"
15 "fagott.pw/grilist/cache"
15 16
16 "github.com/julienschmidt/httprouter" 17 "github.com/julienschmidt/httprouter"
17) 18)
18 19
20type CachedGril struct {
21 Created time.Time
22 Gril *Gril
23}
24
19var ( 25var (
20 pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`) 26 pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`)
21 pgValueIdx int 27 pgValueIdx int
@@ -32,6 +38,7 @@ func findIdx() {
32 38
33type GrilsModule struct { 39type GrilsModule struct {
34 g *grilist.Grilist 40 g *grilist.Grilist
41 c *cache.Cache
35} 42}
36 43
37func (m *GrilsModule) Name() string { 44func (m *GrilsModule) Name() string {
@@ -43,6 +50,8 @@ func (m *GrilsModule) Init(g *grilist.Grilist) {
43 m.g = g 50 m.g = g
44 m.g.Router.GET("/gril/:id", m.viewGril) 51 m.g.Router.GET("/gril/:id", m.viewGril)
45 m.g.Router.GET("/gril/:id/*rest", m.viewGril) 52 m.g.Router.GET("/gril/:id/*rest", m.viewGril)
53
54 m.c = cache.New()
46} 55}
47 56
48func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) { 57func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) {
@@ -143,6 +152,10 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
143} 152}
144 153
145func (m *GrilsModule) FromID(id int) (*Gril, error) { 154func (m *GrilsModule) FromID(id int) (*Gril, error) {
155 if g, ok := m.c.Get(id); ok {
156 return g.(*Gril), nil
157 }
158
146 gril := &Gril{ 159 gril := &Gril{
147 ID: id, 160 ID: id,
148 } 161 }
@@ -155,6 +168,7 @@ func (m *GrilsModule) FromID(id int) (*Gril, error) {
155 if err != nil { 168 if err != nil {
156 return nil, err 169 return nil, err
157 } 170 }
171 m.c.Insert(id, gril)
158 return gril, nil 172 return gril, nil
159} 173}
160 174