1
0
forked from MTSR/mapserver

mapdb stub

This commit is contained in:
NatureFreshMilk 2019-01-18 13:50:59 +01:00
parent 49a7de02fc
commit 08407ce0da
6 changed files with 67 additions and 40 deletions

View File

@ -7,11 +7,11 @@ import (
) )
type Config struct { type Config struct {
Port int `json:"port"` Port int `json:"port"`
EnableInitialRendering bool `json:"enableinitialrendering"` EnableInitialRendering bool `json:"enableinitialrendering"`
EnableIncrementalUpdate bool `json:"enableincrementalupdate"` EnableIncrementalUpdate bool `json:"enableincrementalupdate"`
Webdev bool `json:"webdev"` Webdev bool `json:"webdev"`
WebApi WebApiConfig `json:"webapi"` WebApi WebApiConfig `json:"webapi"`
} }
type WebApiConfig struct { type WebApiConfig struct {
@ -24,11 +24,11 @@ func ParseConfig(filename string) (*Config, error) {
} }
cfg := Config{ cfg := Config{
Port: 8080, Port: 8080,
EnableInitialRendering: true, EnableInitialRendering: true,
EnableIncrementalUpdate: true, EnableIncrementalUpdate: true,
Webdev: false, Webdev: false,
WebApi: webapi, WebApi: webapi,
} }
info, err := os.Stat(filename) info, err := os.Stat(filename)

View File

@ -2,14 +2,14 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"mapserver/app" "mapserver/app"
"mapserver/initialrenderer" "mapserver/initialrenderer"
"mapserver/layerconfig" "mapserver/layerconfig"
"mapserver/params" "mapserver/params"
"mapserver/web"
"mapserver/tileupdate" "mapserver/tileupdate"
"fmt" "mapserver/web"
) )
func main() { func main() {

View File

@ -29,7 +29,7 @@ func (a *MapBlockAccessor) Update(pos coords.MapBlockCoords, mb *mapblockparser.
a.c.Set(key, mb, cache.DefaultExpiration) a.c.Set(key, mb, cache.DefaultExpiration)
} }
func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*mapblockparser.MapBlock, error){ func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*mapblockparser.MapBlock, error) {
blocks, err := a.accessor.FindLatestBlocks(mintime, limit) blocks, err := a.accessor.FindLatestBlocks(mintime, limit)
if err != nil { if err != nil {
@ -38,7 +38,7 @@ func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*map
mblist := make([]*mapblockparser.MapBlock, 0) mblist := make([]*mapblockparser.MapBlock, 0)
for _, block := range(blocks) { for _, block := range blocks {
key := getKey(block.Pos) key := getKey(block.Pos)
mapblock, err := mapblockparser.Parse(block.Data, block.Mtime) mapblock, err := mapblockparser.Parse(block.Data, block.Mtime)

View File

@ -6,7 +6,7 @@ type MapBlock struct {
Mapdata []byte `json:"mapdata"` Mapdata []byte `json:"mapdata"`
Metadata Metadata `json:"metadata"` Metadata Metadata `json:"metadata"`
BlockMapping map[int]string `json:"blockmapping"` BlockMapping map[int]string `json:"blockmapping"`
Mtime int64 `json:"mtime"` Mtime int64 `json:"mtime"`
} }
type Metadata struct { type Metadata struct {

27
mapdb/accessor.go Normal file
View File

@ -0,0 +1,27 @@
package mapdb
import (
"mapserver/coords"
)
type MapData struct {
//mapblock position
MBPos coords.MapBlockCoords
//block position
X, Y, Z int
Type string
Data string
Mtime int64
}
type SearchQuery struct {
//block position (not mapblock)
Pos1, Pos2 coords.MapBlockCoords
Type string
}
type DBAccessor interface {
Migrate() error
GetMapData(q SearchQuery) ([]MapData, error)
SetMapData(pos coords.MapBlockCoords, data []MapData) error
}

View File

@ -1,38 +1,38 @@
package tileupdate package tileupdate
import ( import (
"mapserver/app" "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus" "mapserver/app"
"time" "time"
) )
func Job(ctx *app.App){ func Job(ctx *app.App) {
t := time.Now().Unix() t := time.Now().Unix()
fields := logrus.Fields{ fields := logrus.Fields{
"time": t, "time": t,
} }
logrus.WithFields(fields).Info("Starting incremental update") logrus.WithFields(fields).Info("Starting incremental update")
for true { for true {
mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(t, 1000) mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(t, 1000)
if err != nil { if err != nil {
panic(err) panic(err)
} }
fields = logrus.Fields{ for _, mb := range mblist {
"count": len(mblist), if mb.Mtime > t {
"time": t, t = mb.Mtime + 1
} }
logrus.WithFields(fields).Info("incremental update") }
for _, mb := range(mblist) { fields = logrus.Fields{
if mb.Mtime > t { "count": len(mblist),
t = mb.Mtime+1 "time": t,
} }
} logrus.WithFields(fields).Info("incremental update")
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
} }
} }