From 58261615a7167ce3d105972098cc919271cf0b1c Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Mon, 11 Feb 2019 16:32:39 +0100 Subject: [PATCH] initial render pushdown stub --- server/db/accessor.go | 7 ++++- server/db/postgres/postgres.go | 27 ++--------------- server/db/sqlite/initialblocks.go | 40 +++++++++++++++++++++++++ server/db/sqlite/sqlite.go | 28 ----------------- server/mapblockaccessor/legacyblocks.go | 3 +- 5 files changed, 50 insertions(+), 55 deletions(-) create mode 100644 server/db/sqlite/initialblocks.go diff --git a/server/db/accessor.go b/server/db/accessor.go index 756df4a..30890d7 100644 --- a/server/db/accessor.go +++ b/server/db/accessor.go @@ -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) diff --git a/server/db/postgres/postgres.go b/server/db/postgres/postgres.go index 634ed12..40f428b 100644 --- a/server/db/postgres/postgres.go +++ b/server/db/postgres/postgres.go @@ -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) { diff --git a/server/db/sqlite/initialblocks.go b/server/db/sqlite/initialblocks.go new file mode 100644 index 0000000..0b40fd0 --- /dev/null +++ b/server/db/sqlite/initialblocks.go @@ -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 +} diff --git a/server/db/sqlite/sqlite.go b/server/db/sqlite/sqlite.go index d78808b..92ff63d 100644 --- a/server/db/sqlite/sqlite.go +++ b/server/db/sqlite/sqlite.go @@ -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 { diff --git a/server/mapblockaccessor/legacyblocks.go b/server/mapblockaccessor/legacyblocks.go index 39bfdc5..38e56d8 100644 --- a/server/mapblockaccessor/legacyblocks.go +++ b/server/mapblockaccessor/legacyblocks.go @@ -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