mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Debugging Tool for Hot Topics
This commit is contained in:
@@ -18,9 +18,23 @@ class HotTopic < ActiveRecord::Base
|
||||
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)
|
||||
SELECT t.id, RANDOM()
|
||||
exec_sql("INSERT INTO hot_topics (topic_id,
|
||||
random_bias,
|
||||
random_multiplier,
|
||||
days_ago_bias,
|
||||
days_ago_multiplier,
|
||||
score,
|
||||
hot_topic_type)
|
||||
SELECT t.id,
|
||||
calc.random_bias,
|
||||
1.0,
|
||||
0,
|
||||
1.0,
|
||||
calc.random_bias,
|
||||
1
|
||||
FROM topics AS t
|
||||
INNER JOIN (SELECT id, RANDOM() as random_bias
|
||||
FROM topics) AS calc ON calc.id = t.id
|
||||
WHERE t.deleted_at IS NULL
|
||||
AND t.visible
|
||||
AND (NOT t.archived)
|
||||
@@ -28,12 +42,27 @@ class HotTopic < ActiveRecord::Base
|
||||
AND t.category_id IS NULL")
|
||||
|
||||
# Include high percentile recent topics
|
||||
inserted_count = exec_sql("INSERT INTO hot_topics (topic_id, category_id, score)
|
||||
inserted_count = exec_sql("INSERT INTO hot_topics (topic_id,
|
||||
category_id,
|
||||
random_bias,
|
||||
random_multiplier,
|
||||
days_ago_bias,
|
||||
days_ago_multiplier,
|
||||
score,
|
||||
hot_topic_type)
|
||||
SELECT t.id,
|
||||
t.category_id,
|
||||
((1.0 - (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP-t.created_at)/86400) / :days_ago) * 0.95) +
|
||||
(RANDOM() * 0.05)
|
||||
calc.random_bias,
|
||||
0.05,
|
||||
calc.days_ago_bias,
|
||||
0.95,
|
||||
(calc.random_bias * 0.05) + (days_ago_bias * 0.95),
|
||||
2
|
||||
FROM topics AS t
|
||||
INNER JOIN (SELECT id,
|
||||
RANDOM() as random_bias,
|
||||
((1.0 - (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP-created_at)/86400) / :days_ago) * 0.95) AS days_ago_bias
|
||||
FROM topics) AS calc ON calc.id = t.id
|
||||
WHERE t.deleted_at IS NULL
|
||||
AND t.visible
|
||||
AND (NOT t.closed)
|
||||
@@ -56,16 +85,26 @@ class HotTopic < ActiveRecord::Base
|
||||
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)
|
||||
exec_sql("INSERT INTO hot_topics (topic_id,
|
||||
category_id,
|
||||
random_bias,
|
||||
random_multiplier,
|
||||
days_ago_bias,
|
||||
days_ago_multiplier,
|
||||
score,
|
||||
hot_topic_type)
|
||||
SELECT t.id,
|
||||
t.category_id,
|
||||
RANDOM() * :max_old_score
|
||||
calc.random_bias,
|
||||
:max_old_score,
|
||||
0,
|
||||
1.0,
|
||||
calc.random_bias * :max_old_score,
|
||||
3
|
||||
FROM topics AS t
|
||||
INNER JOIN (SELECT id, RANDOM() as random_bias
|
||||
FROM topics) AS calc ON calc.id = t.id
|
||||
WHERE t.deleted_at IS NULL
|
||||
AND t.visible
|
||||
AND (NOT t.closed)
|
||||
|
||||
@@ -55,6 +55,7 @@ class Topic < ActiveRecord::Base
|
||||
# When we want to temporarily attach some data to a forum topic (usually before serialization)
|
||||
attr_accessor :user_data
|
||||
attr_accessor :posters # TODO: can replace with posters_summary once we remove old list code
|
||||
attr_accessor :topic_list
|
||||
|
||||
|
||||
# The regular order
|
||||
|
||||
@@ -3,9 +3,14 @@ require_dependency 'avatar_lookup'
|
||||
class TopicList
|
||||
include ActiveModel::Serialization
|
||||
|
||||
attr_accessor :more_topics_url, :draft, :draft_key, :draft_sequence
|
||||
attr_accessor :more_topics_url,
|
||||
:draft,
|
||||
:draft_key,
|
||||
:draft_sequence,
|
||||
:filter
|
||||
|
||||
def initialize(current_user, topics)
|
||||
def initialize(filter, current_user, topics)
|
||||
@filter = filter
|
||||
@current_user = current_user
|
||||
@topics_input = topics
|
||||
end
|
||||
@@ -30,6 +35,7 @@ class TopicList
|
||||
@topics.each do |ft|
|
||||
ft.user_data = @topic_lookup[ft.id] if @topic_lookup.present?
|
||||
ft.posters = ft.posters_summary(ft.user_data, @current_user, avatar_lookup: avatar_lookup)
|
||||
ft.topic_list = self
|
||||
end
|
||||
|
||||
return @topics
|
||||
|
||||
Reference in New Issue
Block a user