Changed method for getting random location.

This commit is contained in:
BurnyLlama 2023-08-09 16:58:31 +02:00
parent b8fc3bfa11
commit 384e4b1444

View File

@ -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)