Mercurial > gemma
comparison pkg/controllers/fwa.go @ 5248:8c44b518141a new-fwa
Don't intersect with validities when fetching bottleneck_ids for sections and stretches.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Tue, 12 May 2020 22:35:33 +0200 |
parents | d89f5d75223e |
children | 13e1767b63a1 |
comparison
equal
deleted
inserted
replaced
5247:d89f5d75223e | 5248:8c44b518141a |
---|---|
48 distinct(b.bottleneck_id) | 48 distinct(b.bottleneck_id) |
49 FROM | 49 FROM |
50 %s s, waterway.bottlenecks b | 50 %s s, waterway.bottlenecks b |
51 WHERE | 51 WHERE |
52 ST_Intersects(b.area, s.area) | 52 ST_Intersects(b.area, s.area) |
53 AND s.name = $1 | 53 AND s.name = $1` |
54 AND b.validity && tstzrange($2, $3)` | |
55 | 54 |
56 selectLDCsSQL = ` | 55 selectLDCsSQL = ` |
57 SELECT | 56 SELECT |
58 lower(grwl.validity), | 57 lower(grwl.validity), |
59 upper(grwl.validity), | 58 upper(grwl.validity), |
201 | 200 |
202 ctx := req.Context() | 201 ctx := req.Context() |
203 conn := middleware.GetDBConn(req) | 202 conn := middleware.GetDBConn(req) |
204 | 203 |
205 // Function to extract the bottleneck_id's from the query. | 204 // Function to extract the bottleneck_id's from the query. |
206 var extract func(context.Context, *sql.Conn, string, time.Time, time.Time) (bottlenecks, error) | 205 var extract func(context.Context, *sql.Conn, string) (bottlenecks, error) |
207 | 206 |
208 switch vars["kind"] { | 207 switch vars["kind"] { |
209 case "bottleneck": | 208 case "bottleneck": |
210 extract = extractBottleneck | 209 extract = extractBottleneck |
211 case "stretch": | 210 case "stretch": |
215 default: | 214 default: |
216 http.Error(rw, "Invalid kind type.", http.StatusBadRequest) | 215 http.Error(rw, "Invalid kind type.", http.StatusBadRequest) |
217 return | 216 return |
218 } | 217 } |
219 | 218 |
220 bottlenecks, err := extract(ctx, conn, name, from, to) | 219 bottlenecks, err := extract(ctx, conn, name) |
221 if err != nil { | 220 if err != nil { |
222 log.Printf("error: %v\n", err) | 221 log.Printf("error: %v\n", err) |
223 http.Error(rw, "cannot extract bottlenecks", http.StatusBadRequest) | 222 http.Error(rw, "cannot extract bottlenecks", http.StatusBadRequest) |
224 return | 223 return |
225 } | 224 } |
626 | 625 |
627 func loadSymbolBottlenecksFromTo( | 626 func loadSymbolBottlenecksFromTo( |
628 ctx context.Context, | 627 ctx context.Context, |
629 conn *sql.Conn, | 628 conn *sql.Conn, |
630 what, name string, | 629 what, name string, |
631 from, to time.Time, | |
632 ) (bottlenecks, error) { | 630 ) (bottlenecks, error) { |
633 | 631 |
634 rows, err := conn.QueryContext( | 632 rows, err := conn.QueryContext( |
635 ctx, | 633 ctx, |
636 fmt.Sprintf(selectSymbolBottlenecksSQL, what), | 634 fmt.Sprintf(selectSymbolBottlenecksSQL, what), |
637 name, | 635 name) |
638 from, to) | |
639 if err != nil { | 636 if err != nil { |
640 return nil, err | 637 return nil, err |
641 } | 638 } |
642 defer rows.Close() | 639 defer rows.Close() |
643 | 640 |
656 | 653 |
657 func extractBottleneck( | 654 func extractBottleneck( |
658 _ context.Context, | 655 _ context.Context, |
659 _ *sql.Conn, | 656 _ *sql.Conn, |
660 name string, | 657 name string, |
661 _, _ time.Time, | |
662 ) (bottlenecks, error) { | 658 ) (bottlenecks, error) { |
663 return bottlenecks{{id: name}}, nil | 659 return bottlenecks{{id: name}}, nil |
664 } | 660 } |
665 | 661 |
666 func extractStretch( | 662 func extractStretch( |
667 ctx context.Context, | 663 ctx context.Context, |
668 conn *sql.Conn, | 664 conn *sql.Conn, |
669 name string, | 665 name string, |
670 from, to time.Time, | |
671 ) (bottlenecks, error) { | 666 ) (bottlenecks, error) { |
672 return loadSymbolBottlenecksFromTo( | 667 return loadSymbolBottlenecksFromTo( |
673 ctx, | 668 ctx, |
674 conn, | 669 conn, |
675 "users.stretches", name, | 670 "users.stretches", name) |
676 from, to) | |
677 } | 671 } |
678 | 672 |
679 func extractSection( | 673 func extractSection( |
680 ctx context.Context, | 674 ctx context.Context, |
681 conn *sql.Conn, | 675 conn *sql.Conn, |
682 name string, | 676 name string, |
683 from, to time.Time, | |
684 ) (bottlenecks, error) { | 677 ) (bottlenecks, error) { |
685 return loadSymbolBottlenecksFromTo( | 678 return loadSymbolBottlenecksFromTo( |
686 ctx, | 679 ctx, |
687 conn, | 680 conn, |
688 "waterway.sections", name, | 681 "waterway.sections", name) |
689 from, to) | |
690 } | 682 } |
691 | 683 |
692 func (bn *bottleneck) loadLimitingValidities( | 684 func (bn *bottleneck) loadLimitingValidities( |
693 ctx context.Context, | 685 ctx context.Context, |
694 conn *sql.Conn, | 686 conn *sql.Conn, |