mirror of
https://github.com/discourse/discourse.git
synced 2025-09-05 08:59:27 +08:00
FIX: Showing Unread(1) when you weren't tracking the topic. Also
includes performance fix when having MANY new or unread topics.
This commit is contained in:
parent
1c51a613b2
commit
9267c162a1
4 changed files with 28 additions and 32 deletions
|
@ -9,7 +9,13 @@ class TopicTrackingState
|
|||
|
||||
CHANNEL = "/user-tracking"
|
||||
|
||||
attr_accessor :user_id, :topic_id, :highest_post_number, :last_read_post_number, :created_at, :category_name
|
||||
attr_accessor :user_id,
|
||||
:topic_id,
|
||||
:highest_post_number,
|
||||
:last_read_post_number,
|
||||
:created_at,
|
||||
:category_name,
|
||||
:notification_level
|
||||
|
||||
def self.publish_new(topic)
|
||||
|
||||
|
@ -57,7 +63,7 @@ class TopicTrackingState
|
|||
|
||||
end
|
||||
|
||||
def self.publish_read(topic_id, last_read_post_number, user_id)
|
||||
def self.publish_read(topic_id, last_read_post_number, user_id, notification_level=nil)
|
||||
|
||||
highest_post_number = Topic.where(id: topic_id).pluck(:highest_post_number).first
|
||||
|
||||
|
@ -67,7 +73,8 @@ class TopicTrackingState
|
|||
payload: {
|
||||
last_read_post_number: last_read_post_number,
|
||||
highest_post_number: highest_post_number,
|
||||
topic_id: topic_id
|
||||
topic_id: topic_id,
|
||||
notification_level: notification_level
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +111,13 @@ class TopicTrackingState
|
|||
new = TopicQuery.new_filter(Topic, "xxx").where_values.join(" AND ").gsub!("'xxx'", treat_as_new_topic_clause)
|
||||
|
||||
sql = <<SQL
|
||||
SELECT u.id AS user_id, topics.id AS topic_id, topics.created_at, highest_post_number, last_read_post_number, c.name AS category_name
|
||||
SELECT u.id AS user_id,
|
||||
topics.id AS topic_id,
|
||||
topics.created_at,
|
||||
highest_post_number,
|
||||
last_read_post_number,
|
||||
c.name AS category_name,
|
||||
tu.notification_level
|
||||
FROM users u
|
||||
FULL OUTER JOIN topics ON 1=1
|
||||
LEFT JOIN topic_users tu ON tu.topic_id = topics.id AND tu.user_id = u.id
|
||||
|
@ -126,6 +139,7 @@ SQL
|
|||
if topic_id
|
||||
sql << " AND topics.id = :topic_id"
|
||||
end
|
||||
sql << " ORDER BY topics.bumped_at DESC LIMIT 500"
|
||||
|
||||
SqlBuilder.new(sql)
|
||||
.map_exec(TopicTrackingState, user_ids: user_ids, topic_id: topic_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue