aboutsummaryrefslogtreecommitdiff
path: root/modules/grils
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2016-03-27 17:46:17 (UTC)
committerjan <jan@ruken.pw>2016-03-27 17:46:17 (UTC)
commitc7f28c0032163075bd21f899c37ae992e3eece80 (patch)
tree18c580c2f260e93ac97ddb4b4ec42bcae7e58254 /modules/grils
parent876530b3da8377e7072824bca5b3844c682eb37a (diff)
temporaer laufzeiten der module (dashboard data) loggen, views angepasst, dashboard in goroutines aufgeteilt, weniger daten fuers listendashboard holen (reduktion von 6s -> 300ms insgesamt)
Diffstat (limited to 'modules/grils')
-rw-r--r--modules/grils/grils.go58
1 files changed, 32 insertions, 26 deletions
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index e6aaa11..fe947bc 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -7,6 +7,7 @@ import (
7 "regexp" 7 "regexp"
8 "strconv" 8 "strconv"
9 "strings" 9 "strings"
10 "time"
10 11
11 "fagott.pw/charakterin" 12 "fagott.pw/charakterin"
12 "fagott.pw/grilist/frontend" 13 "fagott.pw/grilist/frontend"
@@ -96,12 +97,14 @@ func (m *GrilsModule) GetListsOfGril(gril *Gril) error {
96func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { 97func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory {
97 var categories []grilist.DashboardCategory 98 var categories []grilist.DashboardCategory
98 99
100 t1 := time.Now()
99 rows, err := m.g.DB.Query(`SELECT id FROM grilist.grils ORDER BY updated_at DESC LIMIT 5`) 101 rows, err := m.g.DB.Query(`SELECT id FROM grilist.grils ORDER BY updated_at DESC LIMIT 5`)
100 if err != nil { 102 if err != nil {
101 log.Println(err) 103 log.Println(err)
102 return categories 104 return categories
103 } 105 }
104 defer rows.Close() 106 defer rows.Close()
107 log.Printf("get_newest_grils: %dms", time.Since(t1).Nanoseconds()/1000000)
105 108
106 cat := grilist.DashboardCategory{ 109 cat := grilist.DashboardCategory{
107 Title: "Neue Grils", 110 Title: "Neue Grils",
@@ -114,11 +117,13 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
114 continue 117 continue
115 } 118 }
116 119
120 t2 := time.Now()
117 gril, err := m.FromID(id) 121 gril, err := m.FromID(id)
118 if err != nil { 122 if err != nil {
119 log.Println(err) 123 log.Println(err)
120 continue 124 continue
121 } 125 }
126 log.Printf("get_gril_from_id_in_newest_grils: %dms", time.Since(t2).Nanoseconds()/1000000)
122 127
123 cat.Cards = append(cat.Cards, frontend.Card{ 128 cat.Cards = append(cat.Cards, frontend.Card{
124 Title: gril.RomajiName, 129 Title: gril.RomajiName,
@@ -133,6 +138,7 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
133 }) 138 })
134 } 139 }
135 categories = append(categories, cat) 140 categories = append(categories, cat)
141 log.Printf("get_newest_grils_overall: %dms", time.Since(t1).Nanoseconds()/1000000)
136 return categories 142 return categories
137} 143}
138 144
@@ -195,36 +201,36 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou
195 data := m.g.Renderer.DefaultData() 201 data := m.g.Renderer.DefaultData()
196 data["user"] = user 202 data["user"] = user
197 data["gril"] = gril 203 data["gril"] = gril
198 204
199 // ähnliche grils holen 205 // ähnliche grils holen
200 rows, err := m.g.DB.Query(`SELECT gril_id FROM ( 206 rows, err := m.g.DB.Query(`SELECT gril_id FROM (
201 SELECT DISTINCT gril_id FROM gril_appearance WHERE appearance_id IN (SELECT appearance_id FROM gril_appearance WHERE gril_id = $1) 207 SELECT DISTINCT gril_id FROM gril_appearance WHERE appearance_id IN (SELECT appearance_id FROM gril_appearance WHERE gril_id = $1)
202 ) as t 208 ) as t
203 ORDER BY RANDOM() 209 ORDER BY RANDOM()
204 LIMIT 4;`, id) 210 LIMIT 4;`, id)
205 if err != nil { 211 if err != nil {
206 log.Println("could not get similar grils:", err) 212 log.Println("could not get similar grils:", err)
207 http.Error(w, "500", http.StatusInternalServerError) 213 http.Error(w, "500", http.StatusInternalServerError)
208 return 214 return
209 } 215 }
210 216
211 defer rows.Close() 217 defer rows.Close()
212 var similar []*Gril 218 var similar []*Gril
213 for rows.Next() { 219 for rows.Next() {
214 var id int 220 var id int
215 if err := rows.Scan(&id); err != nil { 221 if err := rows.Scan(&id); err != nil {
216 log.Println("error scanning for similar gril:", err) 222 log.Println("error scanning for similar gril:", err)
217 continue 223 continue
218 } 224 }
219 225
220 g, err := m.FromID(id) 226 g, err := m.FromID(id)
221 if err != nil { 227 if err != nil {
222 log.Println("invalid similar gril:", err) 228 log.Println("invalid similar gril:", err)
223 continue 229 continue
224 } 230 }
225 similar = append(similar, g) 231 similar = append(similar, g)
226 } 232 }
227 data["SimilarGrils"] = similar 233 data["SimilarGrils"] = similar
228 234
229 m.g.Renderer.RenderPage("gril", w, data) 235 m.g.Renderer.RenderPage("gril", w, data)
230} 236}