Mercurial > gemma
diff pkg/models/intservices.go @ 915:2ebf677fc2e1 geo-style
Load style data only on demand to not waste menory.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 03 Oct 2018 13:08:23 +0200 |
parents | 876d1f5433be |
children | 6eb45b3c73f6 |
line wrap: on
line diff
--- a/pkg/models/intservices.go Wed Oct 03 02:04:20 2018 +0200 +++ b/pkg/models/intservices.go Wed Oct 03 13:08:23 2018 +0200 @@ -12,10 +12,10 @@ ) type IntEntry struct { - Name string `json:"name"` - Style sql.NullString `json:"-"` // This should be done separately. - WMS bool `json:"wms"` - WFS bool `json:"wfs"` + Name string `json:"name"` + Style bool `json:"style"` + WMS bool `json:"wms"` + WFS bool `json:"wfs"` } type IntServices struct { @@ -24,8 +24,16 @@ } const ( - selectPublishedServices = `SELECT relname, style, as_wms, as_wfs -FROM sys_admin.published_services JOIN pg_class ON name = oid ORDER by relname` + selectServicesSQL = ` +SELECT relname, style IS NOT NULL, as_wms, as_wfs +FROM sys_admin.published_services +JOIN pg_class ON name = oid ORDER by relname` + + selectStyleSQL = ` +SELECT style IS NOT NULL +FROM sys_admin.published_services +JOIN pg_class ON name = oid +WHERE relname = $1` updateStyleSQL = ` UPDATE sys_admin.published_services @@ -35,6 +43,18 @@ var InternalServices = &IntServices{} +func (e *IntEntry) LoadStyle() (string, error) { + var style string + err := auth.RunAs("sys_admin", context.Background(), + func(conn *sql.Conn) error { + return conn.QueryRowContext( + context.Background(), + selectStyleSQL, + e.Name).Scan(&style) + }) + return style, err +} + func UpdateInternalStyle(req *http.Request, name, style string) error { return auth.RunAsSessionUser(req, func(conn *sql.Conn) error { _, err := conn.ExecContext( @@ -88,7 +108,7 @@ return auth.RunAs("sys_admin", context.Background(), func(conn *sql.Conn) error { rows, err := conn.QueryContext( - context.Background(), selectPublishedServices) + context.Background(), selectServicesSQL) if err != nil { return err } @@ -113,9 +133,10 @@ ps.mu.Unlock() } -func InternalAll(IntEntry) bool { return true } -func IntWMS(entry IntEntry) bool { return entry.WMS } -func IntWFS(entry IntEntry) bool { return entry.WFS } +func InternalAll(IntEntry) bool { return true } +func IntWMS(entry IntEntry) bool { return entry.WMS } +func IntWFS(entry IntEntry) bool { return entry.WFS } +func IntWithStyle(entry IntEntry) bool { return entry.Style } func IntByName(name string) func(IntEntry) bool { return func(entry IntEntry) bool { return entry.Name == name } @@ -132,10 +153,6 @@ } } -func IntWithStyle(entry IntEntry) bool { - return entry.Style.Valid -} - func (ps *IntServices) Filter(accept func(IntEntry) bool) []IntEntry { ps.mu.Lock() defer ps.mu.Unlock()