Adding VariantQuery reseed randomization option (#17942)
Prior to this change, we setup our feed variant query to have a cached randomization seed. For a given user this seed is cached for 15 minutes. The goal of this is to provide mostly consistent sort orders on the feed articles during that 15 minute window. With this change, we allow for a feed variant to say ignore the cached seed and generate a new one for this call. I have also added explicit settings to each of the feed variants to reflect our desired intentions for those features. Relates to - forem/forem#17833 - forem/forem#17826 Closes forem/forem#17940
This commit is contained in:
parent
e3c857a7c1
commit
7a4dd3286d
11 changed files with 25 additions and 2 deletions
|
|
@ -85,6 +85,7 @@ module Articles
|
|||
description: config.fetch("description", ""),
|
||||
order_by: catalog.fetch_order_by(config.fetch("order_by")),
|
||||
max_days_since_published: config.fetch("max_days_since_published"),
|
||||
reseed_randomizer_on_each_request: config.fetch("reseed_randomizer_on_each_request"),
|
||||
)
|
||||
end
|
||||
private_class_method :build_with
|
||||
|
|
|
|||
|
|
@ -34,15 +34,23 @@ module Articles
|
|||
:levers, # Array <Articles::Feeds::RelevancyLever::Configured>
|
||||
:order_by, # Articles::Feeds::OrderByLever
|
||||
:max_days_since_published,
|
||||
# when true, each time you call the query you will get different randomized numbers; when
|
||||
# false, the resulting randomized numbers will be the same within a window of time.
|
||||
:reseed_randomizer_on_each_request,
|
||||
keyword_init: true,
|
||||
)
|
||||
) do
|
||||
alias_method :reseed_randomizer_on_each_request?, :reseed_randomizer_on_each_request
|
||||
end
|
||||
|
||||
# @param config [Articles::Feeds::VariantQuery::Config]
|
||||
# @param user [User,NilClass]
|
||||
# @param number_of_articles [Integer, #to_i]
|
||||
# @param page [Integer, #to_i]
|
||||
# @param tag [NilClass] not used
|
||||
# @param seed [Number] used in the `setseed` Postgresql function to set the randomization seed.
|
||||
#
|
||||
# @param seed [Number] used in the `setseed` Postgresql function to set the randomization
|
||||
# seed. This parameter allows the caller (and debugger) to use the same randomization
|
||||
# order in the queries; the hope being that this might help in any debugging.
|
||||
def initialize(config:, user: nil, number_of_articles: 50, page: 1, tag: nil, seed: nil)
|
||||
@user = user
|
||||
@number_of_articles = number_of_articles
|
||||
|
|
@ -297,6 +305,8 @@ module Articles
|
|||
def randomizer_seed_for(seed:, user:)
|
||||
return Float(seed) if seed
|
||||
|
||||
return rand if config.reseed_randomizer_on_each_request?
|
||||
|
||||
# This is added as a short-circuit in-case the caching proves to be non-performant. Once
|
||||
# this has been merged, given that it's part of the main loop, we can remove the FeatureFlag
|
||||
# a week or so after we merge.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"max_days_since_published": 15,
|
||||
"reseed_randomizer_on_each_request": false,
|
||||
"order_by": "relevancy_score_and_publication_date",
|
||||
"levers": {
|
||||
"daily_decay": {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"max_days_since_published": 15,
|
||||
"reseed_randomizer_on_each_request": false,
|
||||
"order_by": "relevancy_score_and_publication_date",
|
||||
"levers": {
|
||||
"daily_decay": {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"max_days_since_published": 15,
|
||||
"reseed_randomizer_on_each_request": false,
|
||||
"order_by": "relevancy_score_and_publication_date",
|
||||
"levers": {
|
||||
"daily_decay": {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"max_days_since_published": 15,
|
||||
"reseed_randomizer_on_each_request": false,
|
||||
"order_by": "relevancy_score_and_publication_date",
|
||||
"levers": {
|
||||
"daily_decay": {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"max_days_since_published": 15,
|
||||
"reseed_randomizer_on_each_request": false,
|
||||
"order_by": "relevancy_score_and_publication_date",
|
||||
"levers": {
|
||||
"featured_article": { "cases": [[1, 1]], "fallback": 0.85 },
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"max_days_since_published": 15,
|
||||
"reseed_randomizer_on_each_request": false,
|
||||
"description": "As 202205518-variant but with modificiation to `matching_positive_tags_intersection_count`.",
|
||||
"order_by": "relevancy_score_and_publication_date",
|
||||
"levers": {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"max_days_since_published": 15,
|
||||
"reseed_randomizer_on_each_request": false,
|
||||
"description": "As 202205518-variant but with modificiation to `order_by` lever.",
|
||||
"order_by": "final_order_by_random_weighted_to_score",
|
||||
"levers": {
|
||||
|
|
|
|||
|
|
@ -40,3 +40,7 @@ and as of <2022-05-06 Fri> are:
|
|||
|
||||
- **_max_days_since_published_:** only consider articles that were published no
|
||||
more than the _max_days_since_published_.
|
||||
|
||||
- **_reseed_randomizer_on_each_request_:** when true, each time you call the
|
||||
query you will get different randomized numbers; when false, the resulting
|
||||
randomized numbers will be the same within a window of time.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"max_days_since_published": 15,
|
||||
"reseed_randomizer_on_each_request": false,
|
||||
"order_by": "relevancy_score_and_publication_date",
|
||||
"levers": {
|
||||
"daily_decay": {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue