initial render pushdown stub

This commit is contained in:
NatureFreshMilk 2019-02-11 16:32:39 +01:00
parent 26c3663287
commit 58261615a7
5 changed files with 50 additions and 55 deletions

View File

@ -10,11 +10,16 @@ type Block struct {
Mtime int64
}
type InitialBlocksResult struct {
List []*Block
HasMore bool
}
type DBAccessor interface {
Migrate() error
FindBlocksByMtime(gtmtime int64, limit int) ([]*Block, error)
FindLegacyBlocksByPos(lastpos *coords.MapBlockCoords, limit int) ([]*Block, error)
FindNextInitialBlocks(lastpos *coords.MapBlockCoords, limit int) (*InitialBlocksResult, error)
CountBlocks(frommtime, tomtime int64) (int, error)
GetBlock(pos *coords.MapBlockCoords) (*Block, error)

View File

@ -68,31 +68,8 @@ func (this *PostgresAccessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db
return blocks, nil
}
func (this *PostgresAccessor) FindLegacyBlocksByPos(lastpos *coords.MapBlockCoords, limit int) ([]*db.Block, error) {
blocks := make([]*db.Block, 0)
rows, err := this.db.Query(getLastBlockQuery, lastpos.X, lastpos.Y, lastpos.Z, limit)
if err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var pos int64
var data []byte
var mtime int64
err = rows.Scan(&pos, &data, &mtime)
if err != nil {
return nil, err
}
mb := convertRows(pos, data, mtime)
blocks = append(blocks, mb)
}
return blocks, nil
func (this *PostgresAccessor) FindNextInitialBlocks(lastpos *coords.MapBlockCoords, limit int) (*db.InitialBlocksResult, error) {
return nil, nil
}
func (this *PostgresAccessor) CountBlocks(frommtime, tomtime int64) (int, error) {

View File

@ -0,0 +1,40 @@
package sqlite
import (
_ "github.com/mattn/go-sqlite3"
"mapserver/coords"
"mapserver/db"
)
func (this *Sqlite3Accessor) FindNextInitialBlocks(lastpos *coords.MapBlockCoords, limit int) (*db.InitialBlocksResult, error) {
result := &db.InitialBlocksResult{}
blocks := make([]*db.Block, 0)
pc := coords.CoordToPlain(lastpos)
rows, err := this.db.Query(getLastBlockQuery, pc, limit)
if err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var pos int64
var data []byte
var mtime int64
err = rows.Scan(&pos, &data, &mtime)
if err != nil {
return nil, err
}
mb := convertRows(pos, data, mtime)
blocks = append(blocks, mb)
}
result.List = blocks
return result, nil
}

View File

@ -82,34 +82,6 @@ func (this *Sqlite3Accessor) FindBlocksByMtime(gtmtime int64, limit int) ([]*db.
return blocks, nil
}
func (this *Sqlite3Accessor) FindLegacyBlocksByPos(lastpos *coords.MapBlockCoords, limit int) ([]*db.Block, error) {
blocks := make([]*db.Block, 0)
pc := coords.CoordToPlain(lastpos)
rows, err := this.db.Query(getLastBlockQuery, pc, limit)
if err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var pos int64
var data []byte
var mtime int64
err = rows.Scan(&pos, &data, &mtime)
if err != nil {
return nil, err
}
mb := convertRows(pos, data, mtime)
blocks = append(blocks, mb)
}
return blocks, nil
}
func (db *Sqlite3Accessor) CountBlocks(frommtime, tomtime int64) (int, error) {
rows, err := db.db.Query(countBlocksQuery, frommtime, tomtime)
if err != nil {

View File

@ -28,7 +28,8 @@ func (a *MapBlockAccessor) FindNextLegacyBlocks(lastpos *coords.MapBlockCoords,
}
logrus.WithFields(fields).Debug("FindMapBlocksByPos")
blocks, err := a.accessor.FindLegacyBlocksByPos(lastpos, limit)
nextResult, err := a.accessor.FindNextInitialBlocks(lastpos, limit)
blocks := nextResult.List
if err != nil {
return nil, err