aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/grils/grils.go58
-rw-r--r--modules/lists/lists.go18
2 files changed, 39 insertions, 37 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}
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 3febdba..836f6af 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -180,10 +180,6 @@ func ListsToCards(lists []*List) []frontend.Card {
180 var cards []frontend.Card 180 var cards []frontend.Card
181 181
182 for _, list := range lists { 182 for _, list := range lists {
183 s := "s"
184 if len(list.Grils) == 1 {
185 s = ""
186 }
187 cards = append(cards, frontend.Card{ 183 cards = append(cards, frontend.Card{
188 Title: list.Name, 184 Title: list.Name,
189 Description: list.Description, 185 Description: list.Description,
@@ -194,7 +190,7 @@ func ListsToCards(lists []*List) []frontend.Card {
194 Link: fmt.Sprintf("/list/%d", list.ID), 190 Link: fmt.Sprintf("/list/%d", list.ID),
195 }, 191 },
196 frontend.Action{ 192 frontend.Action{
197 Name: fmt.Sprintf(`<span class="chip">%d gril%s</span>`, len(list.Grils), s), 193 Name: fmt.Sprintf(`<span class="chip">von <a class="purple-text text-lighten-2" style="margin-right: 0px" href="/user/%d/%s">%s</a></span>`, list.Owner.ID, list.Owner.GetName(), list.Owner.GetName()),
198 Link: "#", 194 Link: "#",
199 Disabled: true, 195 Disabled: true,
200 }, 196 },
@@ -214,11 +210,11 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.Dashboar
214 log.Println(err) 210 log.Println(err)
215 return categories 211 return categories
216 } 212 }
217 for _, list := range lists { 213 //for _, list := range lists {
218 if err := m.getListGrils(list); err != nil { 214 //if err := m.getListGrils(list); err != nil {
219 log.Println(err) 215 // log.Println(err)
220 } 216 //}
221 } 217 //}
222 218
223 categories = append(categories, grilist.DashboardCategory{ 219 categories = append(categories, grilist.DashboardCategory{
224 Title: "Neueste Listen", 220 Title: "Neueste Listen",
@@ -230,7 +226,7 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.Dashboar
230 } 226 }
231 227
232 // Listen des Benutzers 228 // Listen des Benutzers
233 lists = m.GetUserLists(user, true) 229 lists = m.GetUserLists(user, false)
234 230
235 categories = append(categories, grilist.DashboardCategory{ 231 categories = append(categories, grilist.DashboardCategory{
236 Title: "Meine Listen", 232 Title: "Meine Listen",