2019-02-11 18:32:39 +03:00
|
|
|
package sqlite
|
|
|
|
|
|
|
|
import (
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
"mapserver/coords"
|
|
|
|
"mapserver/db"
|
2019-02-13 17:44:05 +03:00
|
|
|
"mapserver/settings"
|
2019-02-14 10:34:16 +03:00
|
|
|
"mapserver/layer"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
SETTING_LAST_POS = "last_pos"
|
2019-02-11 18:32:39 +03:00
|
|
|
)
|
|
|
|
|
2019-02-13 17:44:05 +03:00
|
|
|
const getLastBlockQuery = `
|
|
|
|
select pos,data,mtime
|
|
|
|
from blocks b
|
|
|
|
where b.mtime = 0
|
2019-02-14 10:34:16 +03:00
|
|
|
and b.pos >= ?
|
2019-02-13 17:44:05 +03:00
|
|
|
order by b.pos asc, b.mtime asc
|
|
|
|
limit ?
|
|
|
|
`
|
|
|
|
|
2019-02-14 10:34:16 +03:00
|
|
|
func (this *Sqlite3Accessor) FindNextInitialBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*db.InitialBlocksResult, error) {
|
2019-02-11 18:32:39 +03:00
|
|
|
|
|
|
|
result := &db.InitialBlocksResult{}
|
|
|
|
|
|
|
|
blocks := make([]*db.Block, 0)
|
2019-02-13 17:44:05 +03:00
|
|
|
|
2019-02-14 10:34:16 +03:00
|
|
|
lastpos := s.GetInt64(SETTING_LAST_POS, coords.MinPlainCoord)
|
2019-02-11 18:32:39 +03:00
|
|
|
|
2019-02-14 10:34:16 +03:00
|
|
|
rows, err := this.db.Query(getLastBlockQuery, lastpos, limit)
|
2019-02-11 18:32:39 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
for rows.Next() {
|
2019-02-14 10:34:16 +03:00
|
|
|
result.HasMore = true
|
|
|
|
result.UnfilteredCount++
|
|
|
|
|
2019-02-11 18:32:39 +03:00
|
|
|
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)
|
2019-02-13 17:44:05 +03:00
|
|
|
|
2019-02-14 10:34:16 +03:00
|
|
|
// new position
|
|
|
|
lastpos = pos
|
|
|
|
|
|
|
|
blockcoordy := mb.Pos.Y * 16
|
|
|
|
currentlayer := layer.FindLayerByY(layers, blockcoordy)
|
|
|
|
|
|
|
|
if currentlayer != nil {
|
|
|
|
blocks = append(blocks, mb)
|
|
|
|
}
|
2019-02-11 18:32:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
result.List = blocks
|
|
|
|
|
2019-02-13 17:44:05 +03:00
|
|
|
//Save current positions of initial run
|
2019-02-14 10:34:16 +03:00
|
|
|
s.SetInt64(SETTING_LAST_POS, lastpos)
|
2019-02-13 17:44:05 +03:00
|
|
|
|
2019-02-11 18:32:39 +03:00
|
|
|
return result, nil
|
|
|
|
}
|