aboutsummaryrefslogtreecommitdiff
path: root/modules/grils
diff options
context:
space:
mode:
authorrtz12 <koenig@fagott.pw>2016-10-03 12:34:36 (UTC)
committerrtz12 <koenig@fagott.pw>2016-10-03 12:34:36 (UTC)
commitc1d895a7db943b758bfbf214c3727569976f85e0 (patch)
tree09d50f05049095b92456c78b3df7fb074fbd53e3 /modules/grils
parent5997487fc5cc2126fb5afa12b75b67f3985e11d2 (diff)
Formatierung gefixt und go fmt
Ein gewisser jemand sollte endlich mal seinen Editor richtig konfigurieren
Diffstat (limited to 'modules/grils')
-rw-r--r--modules/grils/grils.go128
1 files changed, 64 insertions, 64 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}