1
0
forked from MTSR/mapserver

sqlite impl

This commit is contained in:
NatureFreshMilk 2019-02-14 08:34:16 +01:00
parent f9d0b78013
commit 0e169d2b45
8 changed files with 61 additions and 22 deletions

View File

@ -15,7 +15,7 @@ type Config struct {
EnableRendering bool `json:"enablerendering"`
Webdev bool `json:"webdev"`
WebApi *WebApiConfig `json:"webapi"`
Layers []layer.Layer `json:"layers"`
Layers []*layer.Layer `json:"layers"`
RenderingFetchLimit int `json:"renderingfetchlimit"`
RenderingJobs int `json:"renderingjobs"`
RenderingQueue int `json:"renderingqueue"`
@ -69,8 +69,8 @@ func ParseConfig(filename string) (*Config, error) {
SecretKey: RandStringRunes(16),
}
layers := []layer.Layer{
layer.Layer{
layers := []*layer.Layer{
&layer.Layer{
Id: 0,
Name: "Base",
From: -16,

View File

@ -7,6 +7,8 @@ const (
maxPositive = modulo / 2
minValue = -1 << (numBitsPerComponent - 1)
maxValue = 1<<(numBitsPerComponent-1) - 1
MinPlainCoord = -34351347711
)
func CoordToPlain(c *MapBlockCoords) int64 {

View File

@ -12,6 +12,16 @@ func init() {
log = logrus.WithFields(logrus.Fields{"prefix": "coords/convert_test"})
}
func TestMinCoord(t *testing.T){
c := NewMapBlockCoords(MinCoord, MinCoord, MinCoord)
pc := CoordToPlain(c)
log.WithFields(logrus.Fields{"coords": c, "plain": pc}).Info("TestMinCoord")
if pc != MinPlainCoord {
t.Fatal("no min match")
}
}
func testCoordConvert(t *testing.T, mb *MapBlockCoords) {
log.WithFields(logrus.Fields{"coords": mb}).Info("MapblockCoords")

View File

@ -14,6 +14,7 @@ type Block struct {
type InitialBlocksResult struct {
List []*Block
UnfilteredCount int
HasMore bool
}

View File

@ -3,6 +3,8 @@ package postgres
import (
"database/sql"
"mapserver/coords"
"mapserver/settings"
"mapserver/layer"
"mapserver/db"
"time"
@ -68,7 +70,7 @@ func (this *PostgresAccessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db
return blocks, nil
}
func (this *PostgresAccessor) FindNextInitialBlocks(lastpos *coords.MapBlockCoords, limit int) (*db.InitialBlocksResult, error) {
func (this *PostgresAccessor) FindNextInitialBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*db.InitialBlocksResult, error) {
return nil, nil
}

View File

@ -5,39 +5,41 @@ import (
"mapserver/coords"
"mapserver/db"
"mapserver/settings"
"mapserver/layer"
)
const (
SETTING_LAST_POS = "last_pos"
)
const getLastBlockQuery = `
select pos,data,mtime
from blocks b
where b.mtime = 0
and b.pos > ?
and b.pos >= ?
order by b.pos asc, b.mtime asc
limit ?
`
func (this *Sqlite3Accessor) FindNextInitialBlocks(s settings.Settings, layers []layer.Layer, limit int) (*db.InitialBlocksResult, error) {
func (this *Sqlite3Accessor) FindNextInitialBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*db.InitialBlocksResult, error) {
result := &db.InitialBlocksResult{}
blocks := make([]*db.Block, 0)
lastx := s.GetInt(settings.SETTING_LASTX, coords.MinCoord-1)
lasty := s.GetInt(settings.SETTING_LASTY, coords.MinCoord-1)
lastz := s.GetInt(settings.SETTING_LASTZ, coords.MinCoord-1)
lastcoords := coords.NewMapBlockCoords(lastx, lasty, lastz)
pc := coords.CoordToPlain(lastpos)
lastpos := s.GetInt64(SETTING_LAST_POS, coords.MinPlainCoord)
rows, err := this.db.Query(getLastBlockQuery, pc, limit)
rows, err := this.db.Query(getLastBlockQuery, lastpos, limit)
if err != nil {
return nil, err
}
defer rows.Close()
var newlastpos *coords.MapBlockCoords
for rows.Next() {
result.HasMore = true
result.UnfilteredCount++
var pos int64
var data []byte
var mtime int64
@ -48,17 +50,22 @@ func (this *Sqlite3Accessor) FindNextInitialBlocks(s settings.Settings, layers [
}
mb := convertRows(pos, data, mtime)
newlastpos = mb.Pos
blocks = append(blocks, mb)
// new position
lastpos = pos
blockcoordy := mb.Pos.Y * 16
currentlayer := layer.FindLayerByY(layers, blockcoordy)
if currentlayer != nil {
blocks = append(blocks, mb)
}
}
result.List = blocks
//Save current positions of initial run
s.SetInt(settings.SETTING_LASTX, newlastpos.X)
s.SetInt(settings.SETTING_LASTY, newlastpos.Y)
s.SetInt(settings.SETTING_LASTZ, newlastpos.Z)
s.SetInt64(SETTING_LAST_POS, lastpos)
return result, nil
}

View File

@ -6,3 +6,21 @@ type Layer struct {
To int `json:"to"`
From int `json:"from"`
}
func FindLayerById(layers []*Layer, id int) *Layer {
for _, l := range layers {
if l.Id == id {
return l
}
}
return nil
}
func FindLayerByY(layers []*Layer, y int) *Layer {
for _, l := range layers {
if y >= l.From && y <= l.To {
return l
}
}
return nil
}

View File

@ -4,6 +4,7 @@ import (
"mapserver/coords"
"mapserver/eventbus"
"mapserver/layer"
"mapserver/settings"
"mapserver/mapblockparser"
cache "github.com/patrickmn/go-cache"
@ -12,13 +13,11 @@ import (
type FindNextLegacyBlocksResult struct {
HasMore bool
LastPos *coords.MapBlockCoords
LastMtime int64
List []*mapblockparser.MapBlock
UnfilteredCount int
}
func (a *MapBlockAccessor) FindNextLegacyBlocks(lastpos *coords.MapBlockCoords, limit int, layerfilter []layer.Layer) (*FindNextLegacyBlocksResult, error) {
func (a *MapBlockAccessor) FindNextLegacyBlocks(s settings.Settings, layers []layer.Layer, limit int) (*FindNextLegacyBlocksResult, error) {
fields := logrus.Fields{
"x": lastpos.X,