diff --git a/server/db/accessor.go b/server/db/accessor.go index 30890d7..8ffef70 100644 --- a/server/db/accessor.go +++ b/server/db/accessor.go @@ -2,6 +2,8 @@ package db import ( "mapserver/coords" + "mapserver/settings" + "mapserver/layer" ) type Block struct { @@ -19,7 +21,7 @@ type DBAccessor interface { Migrate() error FindBlocksByMtime(gtmtime int64, limit int) ([]*Block, error) - FindNextInitialBlocks(lastpos *coords.MapBlockCoords, limit int) (*InitialBlocksResult, error) + FindNextInitialBlocks(s settings.Settings, layers []layer.Layer, limit int) (*InitialBlocksResult, error) CountBlocks(frommtime, tomtime int64) (int, error) GetBlock(pos *coords.MapBlockCoords) (*Block, error) diff --git a/server/db/sqlite/initialblocks.go b/server/db/sqlite/initialblocks.go index 0b40fd0..c966989 100644 --- a/server/db/sqlite/initialblocks.go +++ b/server/db/sqlite/initialblocks.go @@ -4,13 +4,29 @@ import ( _ "github.com/mattn/go-sqlite3" "mapserver/coords" "mapserver/db" + "mapserver/settings" ) -func (this *Sqlite3Accessor) FindNextInitialBlocks(lastpos *coords.MapBlockCoords, limit int) (*db.InitialBlocksResult, error) { +const getLastBlockQuery = ` +select pos,data,mtime +from blocks b +where b.mtime = 0 +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) { 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) rows, err := this.db.Query(getLastBlockQuery, pc, limit) @@ -19,6 +35,7 @@ func (this *Sqlite3Accessor) FindNextInitialBlocks(lastpos *coords.MapBlockCoord } defer rows.Close() + var newlastpos *coords.MapBlockCoords for rows.Next() { var pos int64 @@ -31,10 +48,17 @@ func (this *Sqlite3Accessor) FindNextInitialBlocks(lastpos *coords.MapBlockCoord } mb := convertRows(pos, data, mtime) + newlastpos = mb.Pos + 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) + return result, nil } diff --git a/server/db/sqlite/sql.go b/server/db/sqlite/sql.go index ac9c921..56c0c5c 100644 --- a/server/db/sqlite/sql.go +++ b/server/db/sqlite/sql.go @@ -8,15 +8,6 @@ order by b.mtime asc limit ? ` -const getLastBlockQuery = ` -select pos,data,mtime -from blocks b -where b.mtime = 0 -and b.pos > ? -order by b.pos asc, b.mtime asc -limit ? -` - const countBlocksQuery = ` select count(*) from blocks b where b.mtime >= ? and b.mtime <= ? `