docbrown/app/services/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 ability to "seed" feed's SQL randomization (#17827) 2022-06-06 11:58:16 -04:00
attributes.rb Articles update refactoring (#12913) 2021-03-10 13:08:36 +03:00
builder.rb Add tooltip to cover image button describing optimal image ratio (#17779) 2022-06-02 17:44:34 -04:00
creator.rb Remove webhooks and related code (#15827) 2021-12-28 10:56:37 +07:00
destroyer.rb Rubocop fixes (#15892) 2021-12-28 09:11:41 -06:00
enrich_image_attributes.rb Refactor FastImage usage (#16304) 2022-01-26 09:48:03 -05:00
get_user_stickies.rb Optimize GetUserStickies (#13541) 2021-04-27 12:47:49 -04:00
page_view_updater.rb Ensuring we don't track views of author or unpublished (#16143) 2022-01-18 11:23:18 -05:00
suggest.rb Extracting a not_authored_by scope (#16123) 2022-01-17 15:20:49 -05:00
suggest_stickies.rb Extracting a not_authored_by scope (#16123) 2022-01-17 15:20:49 -05:00
updater.rb Context Notifications (#17243) 2022-04-18 10:30:30 +03:00