# HG changeset patch # User Sascha L. Teichmann # Date 1543159601 -3600 # Node ID d753ce6cf5881555a9f60642dcd59bb8f5d82421 # Parent cabf4789e02bf69348c277ace3c098a7fc6b25a0 To make golint happier made context.Context to be the first argument in all calls. diff -r cabf4789e02b -r d753ce6cf588 pkg/controllers/cross.go --- a/pkg/controllers/cross.go Sun Nov 25 15:56:07 2018 +0100 +++ b/pkg/controllers/cross.go Sun Nov 25 16:26:41 2018 +0100 @@ -28,16 +28,17 @@ const WGS84 = 4326 func reproject( + ctx context.Context, rp *models.Reprojector, src models.GeoJSONLineCoordinates, - ctx context.Context, ) (models.GeoJSONLineCoordinates, error) { dst := make(models.GeoJSONLineCoordinates, len(src)) for i, s := range src { var err error if dst[i].Lat, dst[i].Lon, err = rp.Reproject( - s.Lat, s.Lon, ctx, + ctx, + s.Lat, s.Lon, ); err != nil { return nil, err } @@ -50,10 +51,10 @@ ST_Transform(ST_GeomFromWKB($2, $1::integer), 4326))` func projectBack( + ctx context.Context, line octree.MultiLineStringZ, epsg uint32, conn *sql.Conn, - ctx context.Context, ) (models.GeoJSONMultiLineCoordinatesZ, error) { var mls models.GeoJSONMultiLineCoordinatesZ @@ -74,10 +75,11 @@ csi := input.(*models.CrossSectionInput) start := time.Now() + ctx := req.Context() tree, err := octree.Cache.Get( - csi.Properties.Bottleneck, csi.Properties.Date.Time, - conn, req.Context()) + ctx, conn, + csi.Properties.Bottleneck, csi.Properties.Date.Time) log.Printf("loading octree took: %s\n", time.Since(start)) if err != nil { @@ -102,14 +104,14 @@ var rp *models.Reprojector if rp, err = models.NewReprojector( - conn, req.Context(), + ctx, conn, WGS84, tree.EPSG, ); err != nil { return } defer rp.Close() - coords, err := reproject(rp, csi.Geometry.Coordinates, req.Context()) + coords, err := reproject(ctx, rp, csi.Geometry.Coordinates) log.Printf("transforming input coords took: %s\n", time.Since(start)) if err != nil { @@ -149,8 +151,9 @@ var joined models.GeoJSONMultiLineCoordinatesZ joined, err = projectBack( + ctx, segments, tree.EPSG, - conn, req.Context(), + conn, ) log.Printf("projecting back took: %s\n", time.Since(start)) diff -r cabf4789e02b -r d753ce6cf588 pkg/controllers/importqueue.go --- a/pkg/controllers/importqueue.go Sun Nov 25 15:56:07 2018 +0100 +++ b/pkg/controllers/importqueue.go Sun Nov 25 16:26:41 2018 +0100 @@ -362,7 +362,7 @@ if state == "accepted" { if jc := imports.FindJobCreator(imports.JobKind(kind)); jc != nil { - if err = jc.StageDone(tx, ctx, id); err != nil { + if err = jc.StageDone(ctx, tx, id); err != nil { return } } diff -r cabf4789e02b -r d753ce6cf588 pkg/controllers/srimports.go --- a/pkg/controllers/srimports.go Sun Nov 25 15:56:07 2018 +0100 +++ b/pkg/controllers/srimports.go Sun Nov 25 16:26:41 2018 +0100 @@ -229,7 +229,7 @@ messages = append(messages, fmt.Sprintf("'meta.json' found but invalid: %v", err)) } else { - errs := meta.Validate(conn, req.Context()) + errs := meta.Validate(req.Context(), conn) for _, err := range errs { messages = append(messages, fmt.Sprintf("invalid 'meta.json': %v", err)) diff -r cabf4789e02b -r d753ce6cf588 pkg/imports/queue.go --- a/pkg/imports/queue.go Sun Nov 25 15:56:07 2018 +0100 +++ b/pkg/imports/queue.go Sun Nov 25 16:26:41 2018 +0100 @@ -36,7 +36,7 @@ } Job interface { - Do(int64, context.Context, *sql.Conn, Feedback) error + Do(context.Context, int64, *sql.Conn, Feedback) error CleanUp() error } @@ -45,7 +45,7 @@ JobCreator interface { Create(kind JobKind, data string) (Job, error) Depends() []string - StageDone(*sql.Tx, context.Context, int64) error + StageDone(context.Context, *sql.Tx, int64) error } idJob struct { @@ -374,7 +374,7 @@ ctx := context.Background() return auth.RunAs(ctx, idj.user, func(conn *sql.Conn) error { - return job.Do(idj.id, ctx, conn, feedback) + return job.Do(ctx, idj.id, conn, feedback) }) })() if errDo != nil { diff -r cabf4789e02b -r d753ce6cf588 pkg/imports/sr.go --- a/pkg/imports/sr.go Sun Nov 25 15:56:07 2018 +0100 +++ b/pkg/imports/sr.go Sun Nov 25 16:26:41 2018 +0100 @@ -80,8 +80,8 @@ } func (srJobCreator) StageDone( + ctx context.Context, tx *sql.Tx, - ctx context.Context, id int64, ) error { _, err := tx.ExecContext(ctx, srStageDoneSQL, id) @@ -165,8 +165,8 @@ } func (sr *SoundingResult) Do( + ctx context.Context, importID int64, - ctx context.Context, conn *sql.Conn, feedback Feedback, ) error { @@ -188,7 +188,7 @@ return err } - if err := m.Validate(conn, ctx); err != nil { + if err := m.Validate(ctx, conn); err != nil { return common.ToError(err) } @@ -241,7 +241,7 @@ feedback.Info("Triangulate...") start = time.Now() - tin, err := octree.GenerateTinByID(conn, ctx, id, epsg) + tin, err := octree.GenerateTinByID(ctx, conn, id, epsg) feedback.Info("triangulation took %s", time.Since(start)) if err != nil { return err @@ -285,7 +285,7 @@ } // Store for potential later removal. - if err = track(tx, ctx, importID, "waterway.sounding_results", id); err != nil { + if err = track(ctx, tx, importID, "waterway.sounding_results", id); err != nil { return err } diff -r cabf4789e02b -r d753ce6cf588 pkg/imports/track.go --- a/pkg/imports/track.go Sun Nov 25 15:56:07 2018 +0100 +++ b/pkg/imports/track.go Sun Nov 25 16:26:41 2018 +0100 @@ -24,7 +24,7 @@ VALUES ($1, $2::regclass, $3)` ) -func track(tx *sql.Tx, ctx context.Context, importID int64, relation string, key int64) error { +func track(ctx context.Context, tx *sql.Tx, importID int64, relation string, key int64) error { _, err := tx.ExecContext(ctx, trackImportSQL, importID, relation, key) return err } diff -r cabf4789e02b -r d753ce6cf588 pkg/models/reproject.go --- a/pkg/models/reproject.go Sun Nov 25 15:56:07 2018 +0100 +++ b/pkg/models/reproject.go Sun Nov 25 16:26:41 2018 +0100 @@ -29,8 +29,8 @@ } func NewReprojector( + ctx context.Context, conn *sql.Conn, - ctx context.Context, fromEPSG, toEPSG uint32, ) (*Reprojector, error) { stmt, err := conn.PrepareContext(ctx, reprojectSQL) @@ -53,8 +53,8 @@ } func (r *Reprojector) Reproject( + ctx context.Context, x, y float64, - ctx context.Context, ) (v, w float64, err error) { err = r.stmt.QueryRowContext(ctx, x, y, r.FromEPSG, r.ToEPSG).Scan(&v, &w) return diff -r cabf4789e02b -r d753ce6cf588 pkg/models/sr.go --- a/pkg/models/sr.go Sun Nov 25 15:56:07 2018 +0100 +++ b/pkg/models/sr.go Sun Nov 25 16:26:41 2018 +0100 @@ -73,7 +73,7 @@ return err } -func (m *SoundingResultMeta) Validate(conn *sql.Conn, ctx context.Context) []error { +func (m *SoundingResultMeta) Validate(ctx context.Context, conn *sql.Conn) []error { var errs []error diff -r cabf4789e02b -r d753ce6cf588 pkg/octree/cache.go --- a/pkg/octree/cache.go Sun Nov 25 15:56:07 2018 +0100 +++ b/pkg/octree/cache.go Sun Nov 25 16:26:41 2018 +0100 @@ -88,8 +88,9 @@ } func (oc *OctreeCache) Get( + ctx context.Context, + conn *sql.Conn, bottleneck string, date time.Time, - conn *sql.Conn, ctx context.Context, ) (*Tree, error) { oc.Lock() defer oc.Unlock() diff -r cabf4789e02b -r d753ce6cf588 pkg/octree/tin.go --- a/pkg/octree/tin.go Sun Nov 25 15:56:07 2018 +0100 +++ b/pkg/octree/tin.go Sun Nov 25 16:26:41 2018 +0100 @@ -23,7 +23,6 @@ "io" "log" "math" - "time" ) var ( @@ -199,32 +198,12 @@ SELECT ST_AsBinary(ST_Collect(triangles.geom)) FROM triangles, trans WHERE ST_Covers(trans.area, triangles.poly)` - loadTinSQL = tinSQLPrefix + `WHERE bottleneck_id = $2 AND date_info = $3` + tinSQLSuffix loadTinByIDSQL = tinSQLPrefix + `WHERE id = $2` + tinSQLSuffix ) -func GenerateTin( - conn *sql.Conn, +func GenerateTinByID( ctx context.Context, - bottleneck string, - date time.Time, - epsg uint32, -) (*Tin, error) { - var tin Tin - err := conn.QueryRowContext(ctx, loadTinSQL, epsg, bottleneck, date).Scan(&tin) - switch { - case err == sql.ErrNoRows: - return nil, nil - case err != nil: - return nil, err - } - tin.EPSG = epsg - return &tin, nil -} - -func GenerateTinByID( conn *sql.Conn, - ctx context.Context, id int64, epsg uint32, ) (*Tin, error) {