mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Show draft count in user menu and activity (#13812)
This commit adds the number of drafts a user has next to the "Draft" label in the user preferences menu and activity tab. The count is updated via MessageBus when a draft is created or destroyed.
This commit is contained in:
18
db/migrate/20210720221817_add_draft_count_to_user_stat.rb
Normal file
18
db/migrate/20210720221817_add_draft_count_to_user_stat.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddDraftCountToUserStat < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :user_stats, :draft_count, :integer, default: 0, null: false
|
||||
|
||||
execute <<~SQL
|
||||
UPDATE user_stats
|
||||
SET draft_count = new_user_stats.draft_count
|
||||
FROM (SELECT user_stats.user_id, COUNT(drafts.id) draft_count
|
||||
FROM user_stats
|
||||
LEFT JOIN drafts ON user_stats.user_id = drafts.user_id
|
||||
GROUP BY user_stats.user_id) new_user_stats
|
||||
WHERE user_stats.user_id = new_user_stats.user_id
|
||||
AND user_stats.draft_count <> new_user_stats.draft_count
|
||||
SQL
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user