From 95dacf67fa8622580a85036d426f7fac9d2045ab Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Thu, 4 Oct 2018 19:07:36 -0400 Subject: [PATCH] Fix feed issue which caused wrong posts to show up sometimes (#827) --- app/black_box/black_box.rb | 5 +++-- app/controllers/stories_controller.rb | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/black_box/black_box.rb b/app/black_box/black_box.rb index 905c82938..9256ce0ff 100644 --- a/app/black_box/black_box.rb +++ b/app/black_box/black_box.rb @@ -5,10 +5,11 @@ class BlackBox super_super_recent_bonus = article.published_at > 1.hours.ago ? 18 : 0 super_recent_bonus = article.published_at > 3.hours.ago ? 11 : 0 recency_bonus = article.published_at > 11.hours.ago ? 70 : 0 - today_bonus = article.published_at > 26.hours.ago ? 280 : 0 + today_bonus = article.published_at > 26.hours.ago ? 285 : 0 + two_day_bonus = article.published_at > 48.hours.ago ? 120 : 0 FunctionCaller.new("blackbox-production-articleHotness", { article: article, user: article.user }.to_json).call + - reaction_points + recency_bonus + super_recent_bonus + super_super_recent_bonus + today_bonus + reaction_points + recency_bonus + super_recent_bonus + super_super_recent_bonus + today_bonus + two_day_bonus end def self.comment_quality_score(comment) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 2a79bdb21..6717a4615 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -115,12 +115,13 @@ class StoriesController < ApplicationController where("reactions_count > ? OR featured = ?", 10, true). order("hotness_score DESC") if user_signed_in? - offset = [0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7].sample #random offset, weighted more towards zero + offset = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 7].sample #random offset, weighted more towards zero @stories = @stories.offset(offset) end @featured_story = @stories.where.not(main_image: nil).first&.decorate || Article.new if user_signed_in? @new_stories = Article.where("published_at > ? AND score > ?", 4.hours.ago, -30). + where(published: true). includes(:user). limit(45). order("published_at DESC").