mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 23:27:46 +08:00
FIX: Update has_topic_draft when draft is updated (#15219)
Current user state regarding the new topic draft was not updated when the draft was created or destroyed.
This commit is contained in:
@ -207,16 +207,19 @@ class UserStat < ActiveRecord::Base
|
||||
|
||||
def self.update_draft_count(user_id = nil)
|
||||
if user_id.present?
|
||||
draft_count = DB.query_single <<~SQL, user_id: user_id
|
||||
draft_count, has_topic_draft = DB.query_single <<~SQL, user_id: user_id, new_topic: Draft::NEW_TOPIC
|
||||
UPDATE user_stats
|
||||
SET draft_count = (SELECT COUNT(*) FROM drafts WHERE user_id = :user_id)
|
||||
WHERE user_id = :user_id
|
||||
RETURNING draft_count
|
||||
RETURNING draft_count, (SELECT 1 FROM drafts WHERE draft_key = :new_topic)
|
||||
SQL
|
||||
|
||||
MessageBus.publish(
|
||||
'/user',
|
||||
{ draft_count: draft_count.first },
|
||||
{
|
||||
draft_count: draft_count,
|
||||
has_topic_draft: !!has_topic_draft
|
||||
},
|
||||
user_ids: [user_id]
|
||||
)
|
||||
else
|
||||
|
Reference in New Issue
Block a user