add limit param to mapobject search
This commit is contained in:
parent
de4add837a
commit
f42d867d16
@ -68,6 +68,7 @@ type SearchQuery struct {
|
|||||||
Pos2 *coords.MapBlockCoords `json:"pos2"`
|
Pos2 *coords.MapBlockCoords `json:"pos2"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
AttributeLike *SearchAttributeLike `json:"attributelike"`
|
AttributeLike *SearchAttributeLike `json:"attributelike"`
|
||||||
|
Limit *int `json:"limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DBAccessor interface {
|
type DBAccessor interface {
|
||||||
|
@ -10,6 +10,11 @@ func (db *PostgresAccessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobject
|
|||||||
|
|
||||||
var rows *sql.Rows
|
var rows *sql.Rows
|
||||||
var err error
|
var err error
|
||||||
|
var limit = 1000
|
||||||
|
|
||||||
|
if q.Limit != nil {
|
||||||
|
limit = *q.Limit
|
||||||
|
}
|
||||||
|
|
||||||
if q.AttributeLike == nil {
|
if q.AttributeLike == nil {
|
||||||
//plain pos search
|
//plain pos search
|
||||||
@ -17,6 +22,7 @@ func (db *PostgresAccessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobject
|
|||||||
q.Type,
|
q.Type,
|
||||||
q.Pos1.X, q.Pos1.Y, q.Pos1.Z,
|
q.Pos1.X, q.Pos1.Y, q.Pos1.Z,
|
||||||
q.Pos2.X, q.Pos2.Y, q.Pos2.Z,
|
q.Pos2.X, q.Pos2.Y, q.Pos2.Z,
|
||||||
|
limit,
|
||||||
)
|
)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -26,6 +32,7 @@ func (db *PostgresAccessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobject
|
|||||||
q.Pos1.X, q.Pos1.Y, q.Pos1.Z,
|
q.Pos1.X, q.Pos1.Y, q.Pos1.Z,
|
||||||
q.Pos2.X, q.Pos2.Y, q.Pos2.Z,
|
q.Pos2.X, q.Pos2.Y, q.Pos2.Z,
|
||||||
q.AttributeLike.Key, q.AttributeLike.Value,
|
q.AttributeLike.Key, q.AttributeLike.Value,
|
||||||
|
limit,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ where o.type = $1
|
|||||||
and o.posx >= $2 and o.posy >= $3 and o.posz >= $4
|
and o.posx >= $2 and o.posy >= $3 and o.posz >= $4
|
||||||
and o.posx <= $5 and o.posy <= $6 and o.posz <= $7
|
and o.posx <= $5 and o.posy <= $6 and o.posz <= $7
|
||||||
order by o.id
|
order by o.id
|
||||||
|
limit ?8
|
||||||
`
|
`
|
||||||
const getMapDataWithAttributeLikePosQuery = `
|
const getMapDataWithAttributeLikePosQuery = `
|
||||||
select o.id, o.type, o.mtime,
|
select o.id, o.type, o.mtime,
|
||||||
@ -26,6 +27,7 @@ and o.type = $1
|
|||||||
and o.posx >= $2 and o.posy >= $3 and o.posz >= $4
|
and o.posx >= $2 and o.posy >= $3 and o.posz >= $4
|
||||||
and o.posx <= $5 and o.posy <= $6 and o.posz <= $7
|
and o.posx <= $5 and o.posy <= $6 and o.posz <= $7
|
||||||
order by o.id
|
order by o.id
|
||||||
|
limit ?10
|
||||||
`
|
`
|
||||||
|
|
||||||
const removeMapDataQuery = `
|
const removeMapDataQuery = `
|
||||||
|
@ -11,12 +11,18 @@ func (db *Sqlite3Accessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobjectd
|
|||||||
var rows *sql.Rows
|
var rows *sql.Rows
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
var limit = 1000
|
||||||
|
if q.Limit != nil {
|
||||||
|
limit = *q.Limit
|
||||||
|
}
|
||||||
|
|
||||||
if q.AttributeLike == nil {
|
if q.AttributeLike == nil {
|
||||||
//plain pos search
|
//plain pos search
|
||||||
rows, err = db.db.Query(getMapDataPosQuery,
|
rows, err = db.db.Query(getMapDataPosQuery,
|
||||||
q.Type,
|
q.Type,
|
||||||
q.Pos1.X, q.Pos1.Y, q.Pos1.Z,
|
q.Pos1.X, q.Pos1.Y, q.Pos1.Z,
|
||||||
q.Pos2.X, q.Pos2.Y, q.Pos2.Z,
|
q.Pos2.X, q.Pos2.Y, q.Pos2.Z,
|
||||||
|
limit,
|
||||||
)
|
)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -26,6 +32,7 @@ func (db *Sqlite3Accessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobjectd
|
|||||||
q.Type,
|
q.Type,
|
||||||
q.Pos1.X, q.Pos1.Y, q.Pos1.Z,
|
q.Pos1.X, q.Pos1.Y, q.Pos1.Z,
|
||||||
q.Pos2.X, q.Pos2.Y, q.Pos2.Z,
|
q.Pos2.X, q.Pos2.Y, q.Pos2.Z,
|
||||||
|
limit,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ where o.type = ?
|
|||||||
and o.posx >= ? and o.posy >= ? and o.posz >= ?
|
and o.posx >= ? and o.posy >= ? and o.posz >= ?
|
||||||
and o.posx <= ? and o.posy <= ? and o.posz <= ?
|
and o.posx <= ? and o.posy <= ? and o.posz <= ?
|
||||||
order by o.id
|
order by o.id
|
||||||
|
limit ?
|
||||||
`
|
`
|
||||||
|
|
||||||
const getMapDataWithAttributeLikePosQuery = `
|
const getMapDataWithAttributeLikePosQuery = `
|
||||||
@ -27,6 +28,7 @@ and o.type = ?
|
|||||||
and o.posx >= ? and o.posy >= ? and o.posz >= ?
|
and o.posx >= ? and o.posy >= ? and o.posz >= ?
|
||||||
and o.posx <= ? and o.posy <= ? and o.posz <= ?
|
and o.posx <= ? and o.posy <= ? and o.posz <= ?
|
||||||
order by o.id
|
order by o.id
|
||||||
|
limit ?
|
||||||
`
|
`
|
||||||
|
|
||||||
const removeMapDataQuery = `
|
const removeMapDataQuery = `
|
||||||
|
Loading…
Reference in New Issue
Block a user