mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: New way to dismiss new topics (#11927)
This is a try to simplify logic around dismiss new topics to have one solution to work in all places - dismiss all-new, dismiss new in a specific category or even in a specific tag.
This commit is contained in:
committed by
GitHub
parent
151193bb11
commit
f39e7fe81d
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CreateDismissedTopicUsersTable < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :dismissed_topic_users do |t|
|
||||
t.integer :user_id
|
||||
t.integer :topic_id
|
||||
t.datetime :created_at
|
||||
end
|
||||
add_index :dismissed_topic_users, %i(user_id topic_id), unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MoveCategoryLastSeenAtToNewTable < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
sql = <<~SQL
|
||||
INSERT INTO dismissed_topic_users (user_id, topic_id, created_at)
|
||||
SELECT users.id, topics.id, category_users.last_seen_at
|
||||
FROM category_users
|
||||
JOIN users ON users.id = category_users.user_id
|
||||
JOIN categories ON categories.id = category_users.category_id
|
||||
JOIN user_stats ON user_stats.user_id = users.id
|
||||
JOIN user_options ON user_options.user_id = users.id
|
||||
JOIN topics ON topics.category_id = category_users.category_id
|
||||
WHERE category_users.last_seen_at IS NOT NULL
|
||||
AND topics.created_at >= GREATEST(CASE
|
||||
WHEN COALESCE(user_options.new_topic_duration_minutes, :default_duration) = :always THEN users.created_at
|
||||
WHEN COALESCE(user_options.new_topic_duration_minutes, :default_duration) = :last_visit THEN COALESCE(users.previous_visit_at,users.created_at)
|
||||
ELSE (:now::timestamp - INTERVAL '1 MINUTE' * COALESCE(user_options.new_topic_duration_minutes, :default_duration))
|
||||
END, user_stats.new_since, :min_date)
|
||||
AND topics.created_at <= category_users.last_seen_at
|
||||
ORDER BY topics.created_at DESC
|
||||
LIMIT :max_new_topics
|
||||
SQL
|
||||
sql = DB.sql_fragment(sql,
|
||||
now: DateTime.now,
|
||||
last_visit: User::NewTopicDuration::LAST_VISIT,
|
||||
always: User::NewTopicDuration::ALWAYS,
|
||||
default_duration: SiteSetting.default_other_new_topic_duration_minutes,
|
||||
min_date: Time.at(SiteSetting.min_new_topics_time).to_datetime,
|
||||
max_new_topics: SiteSetting.max_new_topics)
|
||||
DB.exec(sql)
|
||||
end
|
||||
|
||||
def down
|
||||
raise IrriversibleMigration
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user