# HG changeset patch # User Sascha L. Teichmann # Date 1562864062 -7200 # Node ID 45be361f2d488acc4469ad9fd6a5dd1447e653dc # Parent 90496300311d00803ce78df8feecd5cbc009225c If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache. diff -r 90496300311d -r 45be361f2d48 pkg/controllers/system.go --- a/pkg/controllers/system.go Thu Jul 11 17:26:09 2019 +0200 +++ b/pkg/controllers/system.go Thu Jul 11 18:54:22 2019 +0200 @@ -15,6 +15,7 @@ import ( "bytes" + "context" "database/sql" "fmt" "io/ioutil" @@ -25,6 +26,7 @@ "github.com/gorilla/mux" + "gemma.intevation.de/gemma/pkg/auth" "gemma.intevation.de/gemma/pkg/config" "gemma.intevation.de/gemma/pkg/geoserver" "gemma.intevation.de/gemma/pkg/models" @@ -51,6 +53,9 @@ INSERT INTO sys_admin.system_config (config_key, config_val) VALUES ($1, $2) ON CONFLICT (config_key) DO UPDATE SET config_val = $2` + + deleteSoundingDiffsSQL = ` +DELETE FROM caching.sounding_differences` ) // System status end points @@ -230,13 +235,24 @@ return reconfigureClassBreaks( old, curr, "sounding_differences", - func() { - log.Println( - "todo: Trigger expensive recalculation of sounding differences contours.") - }) + func() { go deleteSoundingDiffs() }) }) } +func deleteSoundingDiffs() { + // TODO: Better do that in import queue? + ctx := context.Background() + + if err := auth.RunAs(ctx, "sys_admin", + func(conn *sql.Conn) error { + _, err := conn.ExecContext(ctx, deleteSoundingDiffsSQL) + return err + }, + ); err != nil { + log.Printf("error: Cleaning sounding diffs cache failed: %v\n", err) + } +} + func setSystemSettings( input interface{}, req *http.Request,