FIX: round the calculated heat values

Views heats like 12135 will become 12000, like ratios like
1.666666666667 will become 1.67.
This commit is contained in:
Neil Lalonde 2019-06-06 15:44:55 -04:00
parent 35da531f1d
commit 1f73a3ba6d
2 changed files with 23 additions and 12 deletions

View File

@ -73,8 +73,19 @@ class HeatSettingsUpdater
elsif SiteSetting.get(name) == 0 ||
(new_value.to_f / SiteSetting.get(name) - 1.0).abs >= 0.05
if SiteSetting.get(name) != new_value
SiteSetting.set_and_log(name, new_value)
rounded_new_value = if new_value.is_a?(Integer)
if new_value > 9
digits = new_value.digits.reverse
(digits[0] * 10 + digits[1]) * 10.pow(digits[2..-1].size)
else
new_value
end
else
new_value.round(2)
end
if SiteSetting.get(name) != rounded_new_value
SiteSetting.set_and_log(name, rounded_new_value)
end
end
end

View File

@ -75,14 +75,14 @@ describe HeatSettingsUpdater do
context 'increased activity' do
let!(:hottest_topic1) { Fabricate(:topic, views: 10_100, posts_count: 100, like_count: 230) }
let!(:hottest_topic2) { Fabricate(:topic, views: 10_000, posts_count: 100, like_count: 220) }
let!(:warm_topic1) { Fabricate(:topic, views: 4020, posts_count: 100, like_count: 126) }
let!(:warm_topic2) { Fabricate(:topic, views: 4010, posts_count: 100, like_count: 116) }
let!(:warm_topic3) { Fabricate(:topic, views: 4000, posts_count: 100, like_count: 106) }
let!(:lukewarm_topic1) { Fabricate(:topic, views: 2040, posts_count: 100, like_count: 84) }
let!(:lukewarm_topic2) { Fabricate(:topic, views: 2030, posts_count: 100, like_count: 74) }
let!(:lukewarm_topic3) { Fabricate(:topic, views: 2020, posts_count: 100, like_count: 64) }
let!(:lukewarm_topic4) { Fabricate(:topic, views: 2000, posts_count: 100, like_count: 54) }
let!(:hottest_topic2) { Fabricate(:topic, views: 10_012, posts_count: 100, like_count: 220) }
let!(:warm_topic1) { Fabricate(:topic, views: 4020, posts_count: 99, like_count: 126) }
let!(:warm_topic2) { Fabricate(:topic, views: 4010, posts_count: 99, like_count: 116) }
let!(:warm_topic3) { Fabricate(:topic, views: 4005, posts_count: 99, like_count: 106) }
let!(:lukewarm_topic1) { Fabricate(:topic, views: 2040, posts_count: 99, like_count: 84) }
let!(:lukewarm_topic2) { Fabricate(:topic, views: 2030, posts_count: 99, like_count: 74) }
let!(:lukewarm_topic3) { Fabricate(:topic, views: 2020, posts_count: 99, like_count: 64) }
let!(:lukewarm_topic4) { Fabricate(:topic, views: 2002, posts_count: 99, like_count: 54) }
let!(:cold_topic) { Fabricate(:topic, views: 100, posts_count: 100, like_count: 1) }
it 'changes settings when difference is significant' do
@ -93,8 +93,8 @@ describe HeatSettingsUpdater do
expect(SiteSetting.topic_views_heat_medium).to eq(4000)
expect(SiteSetting.topic_views_heat_low).to eq(2000)
expect(SiteSetting.topic_post_like_heat_high).to eq(2.2)
expect(SiteSetting.topic_post_like_heat_medium).to eq(1.06)
expect(SiteSetting.topic_post_like_heat_low).to eq(0.54)
expect(SiteSetting.topic_post_like_heat_medium).to eq(1.07)
expect(SiteSetting.topic_post_like_heat_low).to eq(0.55)
end
it "doesn't change settings when automatic_topic_heat_values is false" do