comparison pkg/controllers/system.go @ 3929:45be361f2d48

If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 11 Jul 2019 18:54:22 +0200
parents 3fcc4e11fc00
children 49564382ffff
comparison
equal deleted inserted replaced
3928:90496300311d 3929:45be361f2d48
13 13
14 package controllers 14 package controllers
15 15
16 import ( 16 import (
17 "bytes" 17 "bytes"
18 "context"
18 "database/sql" 19 "database/sql"
19 "fmt" 20 "fmt"
20 "io/ioutil" 21 "io/ioutil"
21 "log" 22 "log"
22 "net/http" 23 "net/http"
23 "strings" 24 "strings"
24 "sync" 25 "sync"
25 26
26 "github.com/gorilla/mux" 27 "github.com/gorilla/mux"
27 28
29 "gemma.intevation.de/gemma/pkg/auth"
28 "gemma.intevation.de/gemma/pkg/config" 30 "gemma.intevation.de/gemma/pkg/config"
29 "gemma.intevation.de/gemma/pkg/geoserver" 31 "gemma.intevation.de/gemma/pkg/geoserver"
30 "gemma.intevation.de/gemma/pkg/models" 32 "gemma.intevation.de/gemma/pkg/models"
31 ) 33 )
32 34
49 51
50 updateSettingSQL = ` 52 updateSettingSQL = `
51 INSERT INTO sys_admin.system_config (config_key, config_val) 53 INSERT INTO sys_admin.system_config (config_key, config_val)
52 VALUES ($1, $2) 54 VALUES ($1, $2)
53 ON CONFLICT (config_key) DO UPDATE SET config_val = $2` 55 ON CONFLICT (config_key) DO UPDATE SET config_val = $2`
56
57 deleteSoundingDiffsSQL = `
58 DELETE FROM caching.sounding_differences`
54 ) 59 )
55 60
56 // System status end points 61 // System status end points
57 62
58 func showSystemLog( 63 func showSystemLog(
228 registerReconfigureFunc("morphology_classbreaks_compare", 233 registerReconfigureFunc("morphology_classbreaks_compare",
229 func(old sql.NullString, curr string) (func(), error) { 234 func(old sql.NullString, curr string) (func(), error) {
230 return reconfigureClassBreaks( 235 return reconfigureClassBreaks(
231 old, curr, 236 old, curr,
232 "sounding_differences", 237 "sounding_differences",
233 func() { 238 func() { go deleteSoundingDiffs() })
234 log.Println(
235 "todo: Trigger expensive recalculation of sounding differences contours.")
236 })
237 }) 239 })
240 }
241
242 func deleteSoundingDiffs() {
243 // TODO: Better do that in import queue?
244 ctx := context.Background()
245
246 if err := auth.RunAs(ctx, "sys_admin",
247 func(conn *sql.Conn) error {
248 _, err := conn.ExecContext(ctx, deleteSoundingDiffsSQL)
249 return err
250 },
251 ); err != nil {
252 log.Printf("error: Cleaning sounding diffs cache failed: %v\n", err)
253 }
238 } 254 }
239 255
240 func setSystemSettings( 256 func setSystemSettings(
241 input interface{}, 257 input interface{},
242 req *http.Request, 258 req *http.Request,