Multiple repeated summary mail entries

I’ve been able to reproduce the issue on my local Discourse site by adding a tag to the digest suppress tags site setting and then creating a topic with multiple tags.

The following code causes of the issue: discourse/app/models/topic.rb at main · discourse/discourse · GitHub

    if SiteSetting.digest_suppress_tags.present?
      tag_ids = Tag.where_name(SiteSetting.digest_suppress_tags.split("|")).pluck(:id)
      if tag_ids.present?
        topics =
          topics.joins("LEFT JOIN topic_tags tg ON topics.id = tg.topic_id").where(
            "tg.tag_id NOT IN (?) OR tg.tag_id IS NULL",
            tag_ids,
          )
      end
    end

Edit: I don’t think a LEFT JOIN is needed here. The columns from the joined topic_tags table don’t seem to get used later in the method. The fix could be as simple as:

if SiteSetting.digest_suppress_tags.present?
tag_ids = Tag.where_name(SiteSetting.digest_suppress_tags.split("|")).pluck(:id)
  if tag_ids.present?
  topics =
    topics.where.not(id: TopicTag.where(tag_id: tag_ids).select(:topic_id))
  end
end

I’ll leave it for the Discourse team to figure out the best approach. The for_digest method gets run a lot of times and needs to be efficient.

4 Likes