Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/summarization/entry_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ def inject_into(plugin)
plugin.register_modifier(:topic_query_create_list_topics) do |topics, options|
if Discourse.filters.include?(options[:filter]) && SiteSetting.ai_summarization_enabled &&
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch > 0
topics.includes(:ai_summaries).where(
"ai_summaries.id IS NULL OR ai_summaries.summary_type = ?",
AiSummary.summary_types[:gist],
)
topics
.includes(:ai_summaries)
.where(
"ai_summaries.id IS NULL OR ai_summaries.summary_type = ?",
AiSummary.summary_types[:gist],
)
.references(:ai_summaries)
else
topics
end
Expand Down
37 changes: 37 additions & 0 deletions spec/lib/modules/summarization/entry_point_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,43 @@

expect(serialized[:ai_topic_gist]).to be_nil
end

it "works when the topic has whispers" do
SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}"
admin = Fabricate(:admin)
group.add(admin)
# We are testing a scenario where AR could get confused if we don't use `references`.

first = create_post(raw: "this is the first post", title: "super amazing title")

_whisper =
create_post(
topic_id: first.topic.id,
post_type: Post.types[:whisper],
raw: "this is a whispered reply",
)

Fabricate(:topic_ai_gist, target: first.topic)
topic_id = first.topic.id
TopicUser.update_last_read(admin, topic_id, first.post_number, 1, 1)
TopicUser.change(
admin.id,
topic_id,
notification_level: TopicUser.notification_levels[:tracking],
)

gist_topic = TopicQuery.new(admin).list_unread.topics.find { |t| t.id == topic_id }

serialized =
TopicListItemSerializer.new(
gist_topic,
scope: Guardian.new(admin),
root: false,
filter: :hot,
).as_json

expect(serialized[:ai_topic_gist]).to be_present
end
end
end
end
Expand Down