diff options
author | Jan C <jan@ruken.pw> | 2016-03-28 12:30:15 (UTC) |
---|---|---|
committer | Jan C <jan@ruken.pw> | 2016-03-28 12:30:15 (UTC) |
commit | e8f2412efe55c969390168e3ce0b41200f780a1e (patch) | |
tree | 41a0e692d0ded0113394712f750b730c4f4fa864 /modules/grils/grils.go | |
parent | c7f28c0032163075bd21f899c37ae992e3eece80 (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/grils.go')
-rw-r--r-- | modules/grils/grils.go | 16 |
1 files changed, 15 insertions, 1 deletions
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 | ||
20 | type CachedGril struct { | ||
21 | Created time.Time | ||
22 | Gril *Gril | ||
23 | } | ||
24 | |||
19 | var ( | 25 | var ( |
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 | ||
33 | type GrilsModule struct { | 39 | type GrilsModule struct { |
34 | g *grilist.Grilist | 40 | g *grilist.Grilist |
41 | c *cache.Cache | ||
35 | } | 42 | } |
36 | 43 | ||
37 | func (m *GrilsModule) Name() string { | 44 | func (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 | ||
48 | func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) { | 57 | func (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 | ||
145 | func (m *GrilsModule) FromID(id int) (*Gril, error) { | 154 | func (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 | ||