Changed method for getting random location.

main
BurnyLlama 2023-08-09 16:58:31 +02:00
parent b8fc3bfa11
commit 384e4b1444
1 changed files with 8 additions and 1 deletions

View File

@ -17,7 +17,14 @@ impl Location {
) -> Result<Location, sqlx::Error> {
sqlx::query_as!(
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
)
.fetch_one(&db.pool)