mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-22 19:01:32 +00:00
only call random_smallint once for filter
This commit is contained in:
parent
bd020ebb0f
commit
77aea3362e
1 changed files with 5 additions and 1 deletions
|
@ -252,7 +252,11 @@ impl Community {
|
|||
.filter(
|
||||
community::id.nullable().eq(coalesce_2_nullable(
|
||||
try_pick()
|
||||
.filter(community::random_number.ge(random_smallint()))
|
||||
.filter(community::random_number.nullable().ge(
|
||||
// Without `select` and `single_value`, this would call `random_smallint` separately
|
||||
// for each row
|
||||
select(random_smallint()).single_value(),
|
||||
))
|
||||
.single_value(),
|
||||
// Wrap to the beginning if the generated number is higher than all
|
||||
// `community::random_number` values, just like in the MediaWiki algorithm
|
||||
|
|
Loading…
Reference in a new issue