From f1cfe29b1fa0a293506ffb5d148a46f7c950baf8 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Tue, 13 Jan 2015 12:41:05 -0600 Subject: [PATCH] fix initial story hotness Initial story hotness was zero, which excluded stories with no other upvotes from the homepage. Before creating, define initial hotness to something. Since this now makes very new stories show up on the homepage right away, expand the window back to 48 hours. This requires a Story.recalculate_all_hotnesses! to properly sort things. --- app/models/story.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/story.rb b/app/models/story.rb index 9300544..03db39d 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -36,6 +36,7 @@ class Story < ActiveRecord::Base before_validation :assign_short_id_and_upvote, :on => :create + before_create :assign_initial_hotness before_save :log_moderation after_create :mark_submitter, :record_initial_upvote after_save :update_merged_into_story_comments @@ -126,6 +127,10 @@ class Story < ActiveRecord::Base h end + def assign_initial_hotness + self.hotness = self.calculated_hotness + end + def assign_short_id_and_upvote self.short_id = ShortId.new(self.class).generate self.upvotes = 1 @@ -154,9 +159,10 @@ class Story < ActiveRecord::Base end # TODO: as the site grows, shrink this down to 12 or so. - window = 60 * 60 * 24 + window = 60 * 60 * 48 - return -((order * sign) + base + (self.created_at.to_f / window)).round(7) + return -((order * sign) + base + + ((self.created_at || Time.now).to_f / window)).round(7) end def can_be_seen_by_user?(user)