Exclude older topics from the first x rows in "Hot"
This commit is contained in:
parent
9e269fbc7c
commit
422dbbd25a
|
@ -15,7 +15,7 @@ class HotTopic < ActiveRecord::Base
|
|||
hot_percentile = 0.2 # What percentile of topics we consider good
|
||||
older_percentage = 0.2 # how many old topics we want as a percentage
|
||||
new_days = 21 # how many days old we consider old
|
||||
|
||||
no_old_in_first_x_rows = 8 # don't show old results in the first x rows
|
||||
|
||||
# Include all sticky uncategorized on Hot
|
||||
exec_sql("INSERT INTO hot_topics (topic_id, score)
|
||||
|
@ -28,10 +28,11 @@ class HotTopic < ActiveRecord::Base
|
|||
AND t.category_id IS NULL")
|
||||
|
||||
# Include high percentile recent topics
|
||||
exec_sql("INSERT INTO hot_topics (topic_id, category_id, score)
|
||||
inserted_count = exec_sql("INSERT INTO hot_topics (topic_id, category_id, score)
|
||||
SELECT t.id,
|
||||
t.category_id,
|
||||
((1.0 - (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP-t.created_at)/86400) / :days_ago) * 0.95) + (RANDOM() * 0.05)
|
||||
((1.0 - (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP-t.created_at)/86400) / :days_ago) * 0.95) +
|
||||
(RANDOM() * 0.05)
|
||||
FROM topics AS t
|
||||
WHERE t.deleted_at IS NULL
|
||||
AND t.visible
|
||||
|
@ -48,11 +49,22 @@ class HotTopic < ActiveRecord::Base
|
|||
private_message: Archetype::private_message,
|
||||
days_ago: new_days)
|
||||
|
||||
max_old_score = 1.0
|
||||
|
||||
# Finding the highest score in the first x rows
|
||||
if HotTopic.count > no_old_in_first_x_rows
|
||||
max_old_score = HotTopic.order('score desc').limit(no_old_in_first_x_rows).last.score
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Add a sprinkling of random older topics
|
||||
exec_sql("INSERT INTO hot_topics (topic_id, category_id, score)
|
||||
SELECT t.id,
|
||||
t.category_id,
|
||||
RANDOM()
|
||||
RANDOM() * :max_old_score
|
||||
FROM topics AS t
|
||||
WHERE t.deleted_at IS NULL
|
||||
AND t.visible
|
||||
|
@ -67,7 +79,8 @@ class HotTopic < ActiveRecord::Base
|
|||
hot_percentile: hot_percentile,
|
||||
limit: (older_percentage * max_hot_topics).round,
|
||||
private_message: Archetype::private_message,
|
||||
days_ago: new_days)
|
||||
days_ago: new_days,
|
||||
max_old_score: max_old_score)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue