docbrown/app/models/articles
Jeremy Friesen 2e19ea9255
Adding ability to "seed" feed's SQL randomization (#17827)
The commit includes three changes that work to allow us to "seed" the
randomization.  When using the same seed, and randomizer should/must
return the same sequence of numbers.

First, I added the "seed" parameter to the variant query.  If you want
the same sequence of random numbers from query to query, pass the same
seed.  Otherwise, we'll use a Ruby generated random seed.

Second, I added a virtual column to the virtual `article_relevancies`
table.  If you provide a seed, and call the query twice, the first row
in each of `article_relevancies` will have the same `randomized_value`,
likewise the second row, etc.

Third, I amended the existing `order_by_lever` that had a `RANDOM()`
postgresql function call.  I replaced that with the `randomized_value`
which is computed based on the provided seed.

Fundamentally the idea is to allow for randomness but introduce possible
repeatability; a hard thing considering that some of the inner selection
criteria is not fixed (e.g. number of reactions can change from moment
to moment).

I wrote a [complimentary blog post][1] to further explain what's
happening.

Related to forem/forem#17826

[1]:https://takeonrules.com/2022/06/03/adding-reproducible-randomization-to-sql-queries/
2022-06-06 11:58:16 -04:00
..
feeds Adding more context to /admin/abtests (#17821) 2022-06-03 11:27:09 -04:00
cached_entity.rb Refactoring to add helper method (#16064) 2022-01-12 11:21:44 -05:00
feeds.rb Adding ability to "seed" feed's SQL randomization (#17827) 2022-06-06 11:58:16 -04:00