comparison pkg/imports/bn.go @ 1658:07f996b0e14a

Bottleneck import: Cleaned up source a bit (removed outdated TODOs).
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 21 Dec 2018 12:15:54 +0100
parents a0982c38eac0
children 897e7cad7e77
comparison
equal deleted inserted replaced
1657:c354631e0018 1658:07f996b0e14a
34 34
35 const ( 35 const (
36 hasBottleneckSQL = ` 36 hasBottleneckSQL = `
37 SELECT true FROM waterway.bottlenecks WHERE bottleneck_id = $1` 37 SELECT true FROM waterway.bottlenecks WHERE bottleneck_id = $1`
38 38
39 insertSQL = ` 39 insertBottleneckSQL = `
40 INSERT INTO waterway.bottlenecks ( 40 INSERT INTO waterway.bottlenecks (
41 bottleneck_id, 41 bottleneck_id,
42 fk_g_fid, 42 fk_g_fid,
43 objnam, 43 objnam,
44 nobjnm, 44 nobjnm,
97 "waterway.bottlenecks", 97 "waterway.bottlenecks",
98 } 98 }
99 } 99 }
100 100
101 const ( 101 const (
102 // TODO: waterway.bottlenecks needs an integer id column.
103 bnStageDoneSQL = ` 102 bnStageDoneSQL = `
104 UPDATE waterway.bottlenecks SET staging_done = true 103 UPDATE waterway.bottlenecks SET staging_done = true
105 WHERE id IN ( 104 WHERE id IN (
106 SELECT key from waterway.track_imports 105 SELECT key from waterway.track_imports
107 WHERE import_id = $1 AND 106 WHERE import_id = $1 AND
176 for _, x := range []struct { 175 for _, x := range []struct {
177 sql string 176 sql string
178 stmt **sql.Stmt 177 stmt **sql.Stmt
179 }{ 178 }{
180 {hasBottleneckSQL, &hasStmt}, 179 {hasBottleneckSQL, &hasStmt},
181 {insertSQL, &insertStmt}, 180 {insertBottleneckSQL, &insertStmt},
182 {trackImportSQL, &trackStmt}, 181 {trackImportSQL, &trackStmt},
183 } { 182 } {
184 var err error 183 var err error
185 if *x.stmt, err = tx.PrepareContext(ctx, x.sql); err != nil { 184 if *x.stmt, err = tx.PrepareContext(ctx, x.sql); err != nil {
186 return nil, err 185 return nil, err
255 feedback.Info("Storing %d bottlenecks took %s", len(nids), time.Since(start)) 254 feedback.Info("Storing %d bottlenecks took %s", len(nids), time.Since(start))
256 if err = tx.Commit(); err == nil { 255 if err = tx.Commit(); err == nil {
257 feedback.Info("Import of bottlenecks was successful") 256 feedback.Info("Import of bottlenecks was successful")
258 } 257 }
259 258
260 // TODO: needs to be filled more useful.
261 summary := struct { 259 summary := struct {
262 Bottlenecks []string `json:"bottlenecks"` 260 Bottlenecks []string `json:"bottlenecks"`
263 }{ 261 }{
264 Bottlenecks: nids, 262 Bottlenecks: nids,
265 } 263 }