Skip to content

Commit

Permalink
feat: Disable caching for maps with params
Browse files Browse the repository at this point in the history
Warn about disabled caching
  • Loading branch information
bemyak committed Oct 18, 2022
1 parent ccdcc46 commit 776c745
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 43 deletions.
36 changes: 0 additions & 36 deletions atlas/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola"
"github.com/go-spatial/tegola/cache"
"github.com/go-spatial/tegola/config"
"github.com/go-spatial/tegola/internal/log"
"github.com/go-spatial/tegola/internal/observer"
"github.com/go-spatial/tegola/observability"
Expand Down Expand Up @@ -79,10 +78,6 @@ type Atlas struct {
// holds a reference to the observer backend
observer observability.Interface

// holds a reference to configured query parameters for maps
// key = map name
params map[string][]config.QueryParameter

// publishBuildInfo indicates if we should publish the build info on change of observer
// this is set by calling PublishBuildInfo, which will publish
// the build info on the observer and insure changes to observer
Expand Down Expand Up @@ -135,7 +130,6 @@ func (a *Atlas) SeedMapTile(ctx context.Context, m Map, z, x, y uint) error {
tile := slippy.NewTile(z, x, y)

// encode the tile
// TODO (bemyak): Make query parameters work with cache
b, err := m.Encode(ctx, tile, nil)
if err != nil {
return err
Expand Down Expand Up @@ -219,36 +213,6 @@ func (a *Atlas) AddMap(m Map) {
a.maps[m.Name] = m
}

// AddParams adds the given query parameters to the atlas params map
// keyed by the map name, with upper-cased tokens
func (a *Atlas) AddParams(name string, params []config.QueryParameter) {
if a == nil {
defaultAtlas.AddParams(name, params)
return
}
if a.params == nil {
a.params = make(map[string][]config.QueryParameter)
}
a.params[name] = params
}

// GetParams returns any configured query parameters for the given
// map by name
func (a *Atlas) GetParams(name string) []config.QueryParameter {
if a == nil {
return defaultAtlas.GetParams(name)
}
return a.params[name]
}

// HasParams returns true if the given map by name has configured query parameters
func (a *Atlas) HasParams(name string) bool {
if a == nil {
return defaultAtlas.HasParams(name)
}
return len(a.params[name]) > 0
}

// GetCache returns the registered cache if one is registered, otherwise nil
func (a *Atlas) GetCache() cache.Interface {
if a == nil {
Expand Down
3 changes: 3 additions & 0 deletions atlas/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"sync"

"github.com/go-spatial/tegola/config"
"github.com/go-spatial/tegola/observability"

"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -54,6 +55,8 @@ type Map struct {
// WGS:84 values), the third value is the zoom level.
Center [3]float64
Layers []Layer
// Params holds configured query parameters
Params []config.QueryParameter

SRID uint64
// MVT output values
Expand Down
5 changes: 1 addition & 4 deletions cmd/internal/register/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func webMercatorMapFromConfigMap(cfg config.Map) (newMap atlas.Map) {
newMap = atlas.NewWebMercatorMap(string(cfg.Name))
newMap.Attribution = SanitizeAttribution(string(cfg.Attribution))
newMap.Params = cfg.Parameters

// convert from env package
for i, v := range cfg.Center {
Expand Down Expand Up @@ -156,10 +157,6 @@ func Maps(a *atlas.Atlas, maps []config.Map, providers map[string]provider.Tiler
newMap.Layers = append(newMap.Layers, layer)
}

if len(m.Parameters) > 0 {
a.AddParams(string(m.Name), m.Parameters)
}

a.AddMap(newMap)
}
return nil
Expand Down
15 changes: 12 additions & 3 deletions cmd/tegola/cmd/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,20 @@ func doWork(ctx context.Context, tileChannel *TileChannel, maps []atlas.Map, con
}(i)
}

nonParamMaps := make([]atlas.Map, 0)

for _, m := range maps {
// we don't support caching for maps with custom parameters
if m.Params != nil || len(m.Params) > 0 {
log.Warnf("caching is disabled for map %s as it has custom parameters configures", m.Name)
}
nonParamMaps = append(nonParamMaps, m)
}

// run through the incoming tiles, and generate the mapTiles as needed.
TileChannelLoop:
for tile := range tileChannel.Channel() {
for m := range maps {

for _, m := range nonParamMaps {
if ctx.Err() != nil {
cleanup = true
break
Expand All @@ -180,7 +189,7 @@ TileChannelLoop:
}

mapTile := MapTile{
MapName: maps[m].Name,
MapName: m.Name,
Tile: tile,
}

Expand Down

0 comments on commit 776c745

Please sign in to comment.