Weigh staff likes higher when calculating scores. New site setting: `staff_like_weight`
can set the factor (default is 3)
This commit is contained in:
parent
8b0b77c161
commit
197909246c
|
@ -202,12 +202,22 @@ class PostAction < ActiveRecord::Base
|
||||||
column = "#{post_action_type.to_s}_count"
|
column = "#{post_action_type.to_s}_count"
|
||||||
delta = deleted_at.nil? ? 1 : -1
|
delta = deleted_at.nil? ? 1 : -1
|
||||||
|
|
||||||
# Voting also changes the sort_order
|
# We probably want to refactor this method to something cleaner.
|
||||||
if post_action_type == :vote
|
case post_action_type
|
||||||
Post.update_all ["vote_count = vote_count + :delta, sort_order = :max - (vote_count + :delta)", delta: delta, max: Topic.max_sort_order], id: post_id
|
when :vote
|
||||||
|
# Voting also changes the sort_order
|
||||||
|
Post.update_all ["vote_count = vote_count + :delta, sort_order = :max - (vote_count + :delta)",
|
||||||
|
delta: delta,
|
||||||
|
max: Topic.max_sort_order], id: post_id
|
||||||
|
when :like
|
||||||
|
# `like_score` is weighted higher for staff accounts
|
||||||
|
Post.update_all ["like_count = like_count + :delta, like_score = like_score + :score_delta",
|
||||||
|
delta: delta,
|
||||||
|
score_delta: user.staff? ? delta * SiteSetting.staff_like_weight : delta], id: post_id
|
||||||
else
|
else
|
||||||
Post.update_all ["#{column} = #{column} + ?", delta], id: post_id
|
Post.update_all ["#{column} = #{column} + ?", delta], id: post_id
|
||||||
end
|
end
|
||||||
|
|
||||||
Topic.update_all ["#{column} = #{column} + ?", delta], id: post.topic_id
|
Topic.update_all ["#{column} = #{column} + ?", delta], id: post.topic_id
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,8 @@ class SiteSetting < ActiveRecord::Base
|
||||||
|
|
||||||
setting(:allow_duplicate_topic_titles, false)
|
setting(:allow_duplicate_topic_titles, false)
|
||||||
|
|
||||||
|
setting(:staff_like_weight, 3)
|
||||||
|
|
||||||
setting(:add_rel_nofollow_to_user_content, true)
|
setting(:add_rel_nofollow_to_user_content, true)
|
||||||
setting(:exclude_rel_nofollow_domains, '')
|
setting(:exclude_rel_nofollow_domains, '')
|
||||||
setting(:post_excerpt_maxlength, 300)
|
setting(:post_excerpt_maxlength, 300)
|
||||||
|
|
|
@ -585,6 +585,7 @@ en:
|
||||||
privacy_policy_url: "If you have a Privacy Policy document hosted elsewhere that you want to use, provide the full URL here."
|
privacy_policy_url: "If you have a Privacy Policy document hosted elsewhere that you want to use, provide the full URL here."
|
||||||
|
|
||||||
newuser_spam_host_threshold: "How many times a new user can post a link to the same host within their `newuser_spam_host_posts` posts before being considered spam."
|
newuser_spam_host_threshold: "How many times a new user can post a link to the same host within their `newuser_spam_host_posts` posts before being considered spam."
|
||||||
|
staff_like_weight: "Extra weighting factor given to likes when performed by staff."
|
||||||
|
|
||||||
notification_types:
|
notification_types:
|
||||||
mentioned: "%{display_username} mentioned you in %{link}"
|
mentioned: "%{display_username} mentioned you in %{link}"
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
class AddLikeScoreToPosts < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :posts, :like_score, :integer, default: 0, null: false
|
||||||
|
|
||||||
|
execute "UPDATE posts p
|
||||||
|
set like_score = x.like_score
|
||||||
|
FROM (SELECT pa.post_id,
|
||||||
|
SUM(CASE
|
||||||
|
WHEN u.admin OR u.moderator THEN 3
|
||||||
|
ELSE 1
|
||||||
|
END) AS like_score
|
||||||
|
FROM post_actions AS pa
|
||||||
|
INNER JOIN users AS u ON u.id = pa.user_id
|
||||||
|
GROUP BY pa.post_id) AS x
|
||||||
|
WHERE x.post_id = p.id"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ class ScoreCalculator
|
||||||
def self.default_score_weights
|
def self.default_score_weights
|
||||||
{
|
{
|
||||||
reply_count: 5,
|
reply_count: 5,
|
||||||
like_count: 15,
|
like_score: 15,
|
||||||
incoming_link_count: 5,
|
incoming_link_count: 5,
|
||||||
bookmark_count: 2,
|
bookmark_count: 2,
|
||||||
avg_time: 0.05,
|
avg_time: 0.05,
|
||||||
|
|
|
@ -122,18 +122,30 @@ describe PostAction do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when a user likes something' do
|
describe 'when a user likes something' do
|
||||||
it 'should increase the post counts when a user likes' do
|
it 'should increase the `like_count` and `like_score` when a user likes something' do
|
||||||
lambda {
|
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
||||||
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
post.reload
|
||||||
post.reload
|
post.like_count.should == 1
|
||||||
}.should change(post, :like_count).by(1)
|
post.like_score.should == 1
|
||||||
end
|
post.topic.reload
|
||||||
|
post.topic.like_count.should == 1
|
||||||
|
|
||||||
it 'should increase the forum topic like count when a user likes' do
|
# When a staff member likes it
|
||||||
lambda {
|
PostAction.act(moderator, post, PostActionType.types[:like])
|
||||||
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
post.reload
|
||||||
post.topic.reload
|
post.like_count.should == 2
|
||||||
}.should change(post.topic, :like_count).by(1)
|
post.like_score.should == 4
|
||||||
|
|
||||||
|
# Removing likes
|
||||||
|
PostAction.remove_act(codinghorror, post, PostActionType.types[:like])
|
||||||
|
post.reload
|
||||||
|
post.like_count.should == 1
|
||||||
|
post.like_score.should == 3
|
||||||
|
|
||||||
|
PostAction.remove_act(moderator, post, PostActionType.types[:like])
|
||||||
|
post.reload
|
||||||
|
post.like_count.should == 0
|
||||||
|
post.like_score.should == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue