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:
Bianca Nenciu
2021-12-08 14:40:35 +02:00
committed by GitHub
parent a144f49ec2
commit 049bc33838
2 changed files with 9 additions and 4 deletions

View File

@ -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