docbrown/app/services/articles/feeds
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
..
article_score_calculator_for_user.rb Extracting a common calculator for feed weights (#15199) 2021-10-27 04:45:53 -04:00
basic.rb Normalizing feed page size (#15326) 2021-11-16 11:12:01 -05:00
find_featured_story.rb Removing WeightedQueryStrategy; use VariantQuery now (#17420) 2022-04-27 09:19:09 -04:00
large_forem_experimental.rb Extracting a not_authored_by scope (#16123) 2022-01-17 15:20:49 -05:00
latest.rb Normalizing feed page size (#15326) 2021-11-16 11:12:01 -05:00
tag.rb Normalizing feed page size (#15326) 2021-11-16 11:12:01 -05:00
timeframe.rb Normalizing feed page size (#15326) 2021-11-16 11:12:01 -05:00
variant_query.rb Adding ability to "seed" feed's SQL randomization (#17827) 2022-06-06 11:58:16 -04:00