aboutsummaryrefslogtreecommitdiff
path: root/modules/grils
diff options
context:
space:
mode:
authorJan C <jan@ruken.pw>2016-03-30 15:12:21 (UTC)
committerJan C <jan@ruken.pw>2016-03-30 15:12:21 (UTC)
commita9e63899ec64280847d220b4640053e74ae73031 (patch)
tree8bf830a9bf0ec8f78f3b93a477c5181269054529 /modules/grils
parent5e34104d93fdbd35d5937816bbb8d45223087043 (diff)
test ohne grils flattened view
Diffstat (limited to 'modules/grils')
-rw-r--r--modules/grils/grils.go65
1 files changed, 60 insertions, 5 deletions
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 791ea5e..116b689 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -159,16 +159,71 @@ func (m *GrilsModule) FromID(id int) (*Gril, error) {
159 gril := &Gril{ 159 gril := &Gril{
160 ID: id, 160 ID: id,
161 } 161 }
162 var tags []byte 162 t1 := time.Now()
163 var otherNames []byte 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 err := m.g.DB.QueryRow(`SELECT kanji_name, romaji_name, other_names, updated_at, age, birthday, tags FROM grilist.grils_flattened WHERE id = $1`, id).Scan(&gril.KanjiName, &gril.RomajiName, &otherNames, &gril.UpdatedAt, &gril.Age, &gril.Birthday, &tags) 164 log.Printf("get_gril_from_id_raw: %dms", time.Since(t1).Nanoseconds()/1000000)
165 165
166 gril.Tags = pgArray(tags)
167 gril.OtherNames = pgArray(otherNames)
168 if err != nil { 166 if err != nil {
169 return nil, err 167 return nil, err
170 } 168 }
169
170 // Namen rausholen
171 rows, err := m.g.DB.Query(`SELECT name, name_type FROM grilist.gril_names WHERE gril_id = $1`, id)
172 if err != nil {
173 return nil, err
174 }
175 log.Printf("get_gril_from_id_names: %dms", time.Since(t1).Nanoseconds()/1000000)
176 defer rows.Close()
177
178 for rows.Next() {
179 var name string
180 var name_type int
181 if err := rows.Scan(&name, &name_type); err != nil {
182 return nil, err
183 }
184
185 switch name_type {
186 case 0:
187 gril.KanjiName = name
188 break
189 case 1:
190 gril.RomajiName = name
191 default:
192 gril.OtherNames = append(gril.OtherNames, name)
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 }
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
171 m.c.Insert(id, gril) 225 m.c.Insert(id, gril)
226 log.Printf("get_gril_from_id: %dms", time.Since(t1).Nanoseconds()/1000000)
172 return gril, nil 227 return gril, nil
173} 228}
174 229