Changed method for getting random location.
This commit is contained in:
parent
b8fc3bfa11
commit
384e4b1444
|
@ -17,7 +17,14 @@ impl Location {
|
||||||
) -> Result<Location, sqlx::Error> {
|
) -> Result<Location, sqlx::Error> {
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Location,
|
Location,
|
||||||
"SELECT id, map, has_entities FROM locations WHERE has_entities = $1 ORDER BY RANDOM() LIMIT 1",
|
"
|
||||||
|
SELECT id, map, has_entities FROM locations
|
||||||
|
WHERE has_entities = $1
|
||||||
|
OFFSET (
|
||||||
|
SELECT floor(random() * (SELECT count(id) FROM locations WHERE has_entities = $1))::int
|
||||||
|
)
|
||||||
|
LIMIT 1
|
||||||
|
",
|
||||||
has_entities
|
has_entities
|
||||||
)
|
)
|
||||||
.fetch_one(&db.pool)
|
.fetch_one(&db.pool)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user