diff --git a/mapobjectdb/accessor.go b/mapobjectdb/accessor.go index ac65b0e..0bb44d3 100644 --- a/mapobjectdb/accessor.go +++ b/mapobjectdb/accessor.go @@ -68,6 +68,7 @@ type SearchQuery struct { Pos2 *coords.MapBlockCoords `json:"pos2"` Type string `json:"type"` AttributeLike *SearchAttributeLike `json:"attributelike"` + Limit *int `json:"limit"` } type DBAccessor interface { diff --git a/mapobjectdb/postgres/mapobjects.go b/mapobjectdb/postgres/mapobjects.go index f0bc76a..6be54e6 100644 --- a/mapobjectdb/postgres/mapobjects.go +++ b/mapobjectdb/postgres/mapobjects.go @@ -10,6 +10,11 @@ func (db *PostgresAccessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobject var rows *sql.Rows var err error + var limit = 1000 + + if q.Limit != nil { + limit = *q.Limit + } if q.AttributeLike == nil { //plain pos search @@ -17,6 +22,7 @@ func (db *PostgresAccessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobject q.Type, q.Pos1.X, q.Pos1.Y, q.Pos1.Z, q.Pos2.X, q.Pos2.Y, q.Pos2.Z, + limit, ) } else { @@ -26,6 +32,7 @@ func (db *PostgresAccessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobject q.Pos1.X, q.Pos1.Y, q.Pos1.Z, q.Pos2.X, q.Pos2.Y, q.Pos2.Z, q.AttributeLike.Key, q.AttributeLike.Value, + limit, ) } diff --git a/mapobjectdb/postgres/sql.go b/mapobjectdb/postgres/sql.go index 726ee3e..a9c00f4 100644 --- a/mapobjectdb/postgres/sql.go +++ b/mapobjectdb/postgres/sql.go @@ -11,6 +11,7 @@ where o.type = $1 and o.posx >= $2 and o.posy >= $3 and o.posz >= $4 and o.posx <= $5 and o.posy <= $6 and o.posz <= $7 order by o.id +limit ?8 ` const getMapDataWithAttributeLikePosQuery = ` 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 <= $5 and o.posy <= $6 and o.posz <= $7 order by o.id +limit ?10 ` const removeMapDataQuery = ` diff --git a/mapobjectdb/sqlite/mapobjects.go b/mapobjectdb/sqlite/mapobjects.go index 3070672..ce5e284 100644 --- a/mapobjectdb/sqlite/mapobjects.go +++ b/mapobjectdb/sqlite/mapobjects.go @@ -11,12 +11,18 @@ func (db *Sqlite3Accessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobjectd var rows *sql.Rows var err error + var limit = 1000 + if q.Limit != nil { + limit = *q.Limit + } + if q.AttributeLike == nil { //plain pos search rows, err = db.db.Query(getMapDataPosQuery, q.Type, q.Pos1.X, q.Pos1.Y, q.Pos1.Z, q.Pos2.X, q.Pos2.Y, q.Pos2.Z, + limit, ) } else { @@ -26,6 +32,7 @@ func (db *Sqlite3Accessor) GetMapData(q *mapobjectdb.SearchQuery) ([]*mapobjectd q.Type, q.Pos1.X, q.Pos1.Y, q.Pos1.Z, q.Pos2.X, q.Pos2.Y, q.Pos2.Z, + limit, ) } diff --git a/mapobjectdb/sqlite/sql.go b/mapobjectdb/sqlite/sql.go index 240f81c..6517bc8 100644 --- a/mapobjectdb/sqlite/sql.go +++ b/mapobjectdb/sqlite/sql.go @@ -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 <= ? order by o.id +limit ? ` 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 <= ? order by o.id +limit ? ` const removeMapDataQuery = `