From 606f5c9849db4ad6413fbaf3090db8d7ee41a8f1 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Tue, 9 Dec 2014 10:07:36 -0600 Subject: [PATCH] experiment with factoring comment scores into story hotness might keep an active story alive on the front page and bury a story with a "comment graveyard" --- app/models/comment.rb | 2 ++ app/models/story.rb | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index b689f00..d59a4a4 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -250,6 +250,8 @@ class Comment < ActiveRecord::Base "downvotes = COALESCE(downvotes, 0) + #{downvote.to_i}, " << "confidence = '#{self.calculated_confidence}' WHERE id = " << "#{self.id.to_i}") + + self.story.recalculate_hotness! end def gone_text diff --git a/app/models/story.rb b/app/models/story.rb index a2e2323..4d6e781 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -138,10 +138,12 @@ class Story < ActiveRecord::Base end # prevent the submitter's own comments from affecting the score - ccount = self.comments.where("user_id != ?", self.user_id).count + cpoints = self.comments.where("user_id <> ?", + self.user_id).select(:upvotes, :downvotes).map{|c| + c.upvotes - c.downvotes }.inject(&:+).to_i # don't immediately kill stories at 0 by bumping up score by one - order = Math.log([ (score + 1).abs + ccount, 1 ].max, base) + order = Math.log([ (score + 1).abs + cpoints, 1 ].max, base) if score > 0 sign = 1 elsif score < 0