comparison pkg/imports/wg.go @ 3551:a5448426e4e2

Only erase gauges that have been requested from ERDMS
author Tom Gottfried <tom@intevation.de>
date Fri, 31 May 2019 14:16:48 +0200
parents ba0339118d9c
children 02951a62e8c6
comparison
equal deleted inserted replaced
3550:c0f8f9ba21a7 3551:a5448426e4e2
65 func (*WaterwayGauge) CleanUp() error { return nil } 65 func (*WaterwayGauge) CleanUp() error { return nil }
66 66
67 const ( 67 const (
68 eraseObsoleteGaugesSQL = ` 68 eraseObsoleteGaugesSQL = `
69 UPDATE waterway.gauges SET erased = true 69 UPDATE waterway.gauges SET erased = true
70 WHERE NOT erased AND isrs_astext(location) <> ALL($1) 70 WHERE NOT erased
71 AND (location).country_code = ANY($1)
72 AND isrs_astext(location) <> ALL($2)
71 RETURNING isrs_astext(location) 73 RETURNING isrs_astext(location)
72 ` 74 `
73 75
74 eraseGaugeSQL = ` 76 eraseGaugeSQL = `
75 WITH upd AS ( 77 WITH upd AS (
182 feedback Feedback, 184 feedback Feedback,
183 ) (interface{}, error) { 185 ) (interface{}, error) {
184 186
185 start := time.Now() 187 start := time.Now()
186 188
187 responseData, err := getRisData( 189 responseData, countries, err := getRisData(
188 ctx, 190 ctx,
189 conn, 191 conn,
190 feedback, 192 feedback,
191 wg.Username, 193 wg.Username,
192 wg.Password, 194 wg.Password,
513 515
514 if len(gauges) == 0 { 516 if len(gauges) == 0 {
515 return nil, UnchangedError("No gauges returned from ERDMS") 517 return nil, UnchangedError("No gauges returned from ERDMS")
516 } 518 }
517 519
518 var pgGauges pgtype.VarcharArray 520 var pgCountries, pgGauges pgtype.VarcharArray
521 pgCountries.Set(countries)
519 pgGauges.Set(gauges) 522 pgGauges.Set(gauges)
520 obsGauges, err := conn.QueryContext(ctx, eraseObsoleteGaugesSQL, &pgGauges) 523 obsGauges, err := conn.QueryContext(ctx,
524 eraseObsoleteGaugesSQL,
525 &pgCountries,
526 &pgGauges)
521 if err != nil { 527 if err != nil {
522 return nil, err 528 return nil, err
523 } 529 }
524 defer obsGauges.Close() 530 defer obsGauges.Close()
525 for obsGauges.Next() { 531 for obsGauges.Next() {