diff --git a/app/models/story.rb b/app/models/story.rb index 59ccb8c..f90c021 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -123,7 +123,11 @@ class Story < ActiveRecord::Base end def self.recalculate_all_hotnesses! - Story.all.order("id DESC").each do |s| + # do the front page first, since find_each can't take an order + Story.order("id DESC").limit(100).each do |s| + s.recalculate_hotness! + end + Story.find_each do |s| s.recalculate_hotness! end true @@ -189,6 +193,8 @@ class Story < ActiveRecord::Base end def calculated_hotness + # take each tag's hotness modifier into effect, and give a slight bump to + # stories submitted by the author base = self.tags.map{|t| t.hotness_mod }.sum + (self.user_is_author ? 0.25 : 0.0) @@ -210,6 +216,12 @@ class Story < ActiveRecord::Base # mix in any stories this one cannibalized cpoints += self.merged_stories.map{|s| s.score }.inject(&:+).to_f + # if a story has many comments but few votes, it's probably a bad story, so + # cap the comment points at the number of upvotes + if cpoints > self.upvotes + cpoints = self.upvotes + end + # don't immediately kill stories at 0 by bumping up score by one order = Math.log([ (score + 1).abs + cpoints, 1 ].max, 10) if score > 0