aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/grils/grils.go128
-rw-r--r--modules/lists/lists.go15
2 files changed, 72 insertions, 71 deletions
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 116b689..3ff03ec 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -6,20 +6,20 @@ import (
6 "net/http" 6 "net/http"
7 "regexp" 7 "regexp"
8 "strconv" 8 "strconv"
9 "time"
10 "strings" 9 "strings"
10 "time"
11 11
12 "fagott.pw/charakterin" 12 "fagott.pw/charakterin"
13 "fagott.pw/grilist/cache"
13 "fagott.pw/grilist/frontend" 14 "fagott.pw/grilist/frontend"
14 "fagott.pw/grilist/grilist" 15 "fagott.pw/grilist/grilist"
15 "fagott.pw/grilist/cache"
16 16
17 "github.com/julienschmidt/httprouter" 17 "github.com/julienschmidt/httprouter"
18) 18)
19 19
20type CachedGril struct { 20type CachedGril struct {
21 Created time.Time 21 Created time.Time
22 Gril *Gril 22 Gril *Gril
23} 23}
24 24
25var ( 25var (
@@ -38,7 +38,7 @@ func findIdx() {
38 38
39type GrilsModule struct { 39type GrilsModule struct {
40 g *grilist.Grilist 40 g *grilist.Grilist
41 c *cache.Cache 41 c *cache.Cache
42} 42}
43 43
44func (m *GrilsModule) Name() string { 44func (m *GrilsModule) Name() string {
@@ -50,8 +50,8 @@ func (m *GrilsModule) Init(g *grilist.Grilist) {
50 m.g = g 50 m.g = g
51 m.g.Router.GET("/gril/:id", m.viewGril) 51 m.g.Router.GET("/gril/:id", m.viewGril)
52 m.g.Router.GET("/gril/:id/*rest", m.viewGril) 52 m.g.Router.GET("/gril/:id/*rest", m.viewGril)
53 53
54 m.c = cache.New() 54 m.c = cache.New()
55} 55}
56 56
57func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) { 57func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) {
@@ -152,77 +152,77 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
152} 152}
153 153
154func (m *GrilsModule) FromID(id int) (*Gril, error) { 154func (m *GrilsModule) FromID(id int) (*Gril, error) {
155 if g, ok := m.c.Get(id); ok { 155 if g, ok := m.c.Get(id); ok {
156 return g.(*Gril), nil 156 return g.(*Gril), nil
157 } 157 }
158 158
159 gril := &Gril{ 159 gril := &Gril{
160 ID: id, 160 ID: id,
161 } 161 }
162 t1 := time.Now() 162 t1 := time.Now()
163 err := m.g.DB.QueryRow(`SELECT updated_at, age, birthday FROM grilist.grils WHERE id = $1`, id).Scan(&gril.UpdatedAt, &gril.Age, &gril.Birthday) 163 err := m.g.DB.QueryRow(`SELECT updated_at, age, birthday FROM grilist.grils WHERE id = $1`, id).Scan(&gril.UpdatedAt, &gril.Age, &gril.Birthday)
164 log.Printf("get_gril_from_id_raw: %dms", time.Since(t1).Nanoseconds()/1000000) 164 log.Printf("get_gril_from_id_raw: %dms", time.Since(t1).Nanoseconds()/1000000)
165 165
166 if err != nil { 166 if err != nil {
167 return nil, err 167 return nil, err
168 } 168 }
169 169
170 // Namen rausholen 170 // Namen rausholen
171 rows, err := m.g.DB.Query(`SELECT name, name_type FROM grilist.gril_names WHERE gril_id = $1`, id) 171 rows, err := m.g.DB.Query(`SELECT name, name_type FROM grilist.gril_names WHERE gril_id = $1`, id)
172 if err != nil { 172 if err != nil {
173 return nil, err 173 return nil, err
174 } 174 }
175 log.Printf("get_gril_from_id_names: %dms", time.Since(t1).Nanoseconds()/1000000) 175 log.Printf("get_gril_from_id_names: %dms", time.Since(t1).Nanoseconds()/1000000)
176 defer rows.Close() 176 defer rows.Close()
177 177
178 for rows.Next() { 178 for rows.Next() {
179 var name string 179 var name string
180 var name_type int 180 var name_type int
181 if err := rows.Scan(&name, &name_type); err != nil { 181 if err := rows.Scan(&name, &name_type); err != nil {
182 return nil, err 182 return nil, err
183 } 183 }
184 184
185 switch name_type { 185 switch name_type {
186 case 0: 186 case 0:
187 gril.KanjiName = name 187 gril.KanjiName = name
188 break 188 break
189 case 1: 189 case 1:
190 gril.RomajiName = name 190 gril.RomajiName = name
191 default: 191 default:
192 gril.OtherNames = append(gril.OtherNames, name) 192 gril.OtherNames = append(gril.OtherNames, name)
193 } 193 }
194 }
195 /*rows, err := m.g.DB.Query(`SELECT name FROM grilist.gril_names WHERE gril_id = $1 AND name_type > 1`, id)
196 if err != nil {
197 return nil, err
198 }
199 defer rows.Close()
200
201 for rows.Next() {
202 var name string
203 if err := rows.Scan(&name); err != nil {
204 return nil, err
205 }
206 gril.OtherNames = append(gril.OtherNames, name)
207 }
208 rows.Close()
209
210 // Tags holen
211 rows, err := m.g.DB.Query(`SELECT name FROM grilist.tags WHERE id IN (SELECT tag_id FROM grilist.grils_tags WHERE gril_id = $1)`, id)
212 if err != nil {
213 return nil, err
214 } 194 }
215 defer rows.Close() 195 /*rows, err := m.g.DB.Query(`SELECT name FROM grilist.gril_names WHERE gril_id = $1 AND name_type > 1`, id)
216 196 if err != nil {
217 for rows.Next() { 197 return nil, err
218 var name string 198 }
219 if err := rows.Scan(&name); err != nil { 199 defer rows.Close()
220 return nil, err 200
221 } 201 for rows.Next() {
222 gril.Tags = append(gril.Tags, name) 202 var name string
223 }*/ 203 if err := rows.Scan(&name); err != nil {
224 204 return nil, err
225 m.c.Insert(id, gril) 205 }
206 gril.OtherNames = append(gril.OtherNames, name)
207 }
208 rows.Close()
209
210 // Tags holen
211 rows, err := m.g.DB.Query(`SELECT name FROM grilist.tags WHERE id IN (SELECT tag_id FROM grilist.grils_tags WHERE gril_id = $1)`, id)
212 if err != nil {
213 return nil, err
214 }
215 defer rows.Close()
216
217 for rows.Next() {
218 var name string
219 if err := rows.Scan(&name); err != nil {
220 return nil, err
221 }
222 gril.Tags = append(gril.Tags, name)
223 }*/
224
225 m.c.Insert(id, gril)
226 log.Printf("get_gril_from_id: %dms", time.Since(t1).Nanoseconds()/1000000) 226 log.Printf("get_gril_from_id: %dms", time.Since(t1).Nanoseconds()/1000000)
227 return gril, nil 227 return gril, nil
228} 228}
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 90de18c..67856fe 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -4,20 +4,21 @@ import (
4 "database/sql" 4 "database/sql"
5 "encoding/json" 5 "encoding/json"
6 "errors" 6 "errors"
7 "fagott.pw/charakterin"
8 "fagott.pw/grilist/cache"
9 "fagott.pw/grilist/frontend"
10 "fagott.pw/grilist/grilist"
11 "fagott.pw/grilist/modules/grils"
12 "fmt" 7 "fmt"
13 "github.com/julienschmidt/httprouter"
14 "github.com/lib/pq"
15 "io/ioutil" 8 "io/ioutil"
16 "log" 9 "log"
17 "net/http" 10 "net/http"
18 "net/url" 11 "net/url"
19 "sort" 12 "sort"
20 "strconv" 13 "strconv"
14
15 "fagott.pw/charakterin"
16 "fagott.pw/grilist/cache"
17 "fagott.pw/grilist/frontend"
18 "fagott.pw/grilist/grilist"
19 "fagott.pw/grilist/modules/grils"
20 "github.com/julienschmidt/httprouter"
21 "github.com/lib/pq"
21) 22)
22 23
23// Module und so. 24// Module und so.