Mercurial > gemma
changeset 5026:d02f0c5c60b3
Simplify deletion of fairway dimensions
Remove filters that duplicate row level security policies and avoid
an extra round-trip to fetch LOS.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 18 Mar 2020 13:04:42 +0100 |
parents | 4c658a8f34da |
children | fa662af56a3d |
files | pkg/imports/fd.go |
diffstat | 1 files changed, 9 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/fd.go Wed Mar 18 12:16:42 2020 +0100 +++ b/pkg/imports/fd.go Wed Mar 18 13:04:42 2020 +0100 @@ -103,16 +103,8 @@ tx *sql.Tx, id int64, ) error { - // We only want to delete the features of the same LOS - // as the imported. - var los int64 - if err := tx.QueryRowContext(ctx, fdFindLOSSQL, id).Scan(&los); err != nil { - // Should always return a row because import will exit as unchanged - // if no new features were found while inserting. - return err - } // Delete the old features. - if _, err := tx.ExecContext(ctx, deleteFairwayDimensionSQL, los); err != nil { + if _, err := tx.ExecContext(ctx, deleteFairwayDimensionSQL, id); err != nil { return err } @@ -134,14 +126,6 @@ } const ( - fdFindLOSSQL = ` -SELECT level_of_service FROM waterway.fairway_dimensions -WHERE id IN ( - SELECT key FROM import.track_imports - WHERE import_id = $1 AND - relation = 'waterway.fairway_dimensions'::regclass) -LIMIT 1` - fdStageDoneSQL = ` UPDATE waterway.fairway_dimensions SET staging_done = true WHERE id IN ( @@ -150,15 +134,15 @@ relation = 'waterway.fairway_dimensions'::regclass)` deleteFairwayDimensionSQL = ` -WITH resp AS ( - SELECT users.current_user_area_utm() AS a -) DELETE FROM waterway.fairway_dimensions -WHERE (pg_has_role('sys_admin', 'MEMBER') - OR ST_Covers((SELECT a FROM resp), - ST_Transform(area::geometry, (SELECT ST_SRID(a) FROM resp)))) - AND staging_done - AND level_of_service = $1::smallint` +WHERE staging_done + AND level_of_service = ( + SELECT DISTINCT level_of_service FROM waterway.fairway_dimensions + WHERE id IN ( + SELECT key FROM import.track_imports + WHERE import_id = $1 + AND relation = 'waterway.fairway_dimensions'::regclass)) +` // The ST_MakeValid and ST_Buffer below are a workarround to // avoid errors due to reprojection.