Story#recalculate_hotness: cap comment points at story votes

This commit is contained in:
Carl Chenet 2017-05-23 13:44:54 +02:00
parent 8fe01e7e2c
commit a05ab9a01e
1 changed files with 13 additions and 1 deletions

View File

@ -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