This repository was archived by the owner on Jul 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +32
-3
lines changed
assets/javascripts/discourse/connectors/topic-list-main-link-bottom
spec/lib/modules/summarization Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import Component from "@glimmer/component";
22
33export default class AiTopicGist extends Component {
44 static shouldRender (outletArgs ) {
5+ debugger ;
56 return outletArgs? .topic ? .ai_topic_gist && ! outletArgs .topic .excerpt ;
67 }
78
Original file line number Diff line number Diff line change @@ -33,14 +33,24 @@ def inject_into(plugin)
3333 :topic_list_item ,
3434 :ai_topic_gist ,
3535 include_condition : -> do
36+ # Hack(roman): Not ideal but at this point I don't have a better way of knowing if I'm serializing items for the hot filter.
37+ # If the association wasn't loaded, assume don't care about summaries, and including it anyway will result in multiple n+1 queries.
38+ # In the future, the serializer could have more informacion about the topic list, so we don't depend on this.
3639 SiteSetting . ai_summarization_enabled &&
37- SiteSetting . ai_summarize_max_hot_topics_gists_per_batch > 0
40+ SiteSetting . ai_summarize_max_hot_topics_gists_per_batch > 0 &&
41+ object . ai_summaries . loaded?
3842 end ,
39- ) { object . ai_summaries . to_a . first &.summarized_text }
43+ ) do
44+ summaries = object . ai_summaries . to_a
45+
46+ # Summaries should always have one element here.
47+ # This is an extra safeguard to avoid including regular summaries.
48+ summaries . find { |s | s . summary_type == "gist" } &.summarized_text
49+ end
4050
4151 # To make sure hot topic gists are inmediately up to date, we rely on this event
4252 # instead of using a scheduled job.
43- plugin . on ( :topic_hot_scores_updated ) { Jobs . enqueue ( :summarize_hot_topics_batch ) }
53+ plugin . on ( :topic_hot_scores_updated ) { Jobs . enqueue ( :hot_topics_gist_batch ) }
4454 end
4555 end
4656 end
Original file line number Diff line number Diff line change 5959
6060 expect ( serialized [ :ai_topic_gist ] ) . to be_present
6161 end
62+
63+ it "doesn't include the summary when looking at other topic lists" do
64+ gist_topic = topic_query . list_latest . topics . find { |t | t . id == topic_ai_gist . target_id }
65+
66+ serialized =
67+ TopicListItemSerializer . new ( gist_topic , scope : Guardian . new , root : false ) . as_json
68+
69+ expect ( serialized [ :ai_topic_gist ] ) . to be_nil
70+ end
6271 end
6372 end
6473 end
6574 end
75+
76+ describe "#on topic_hot_scores_updated" do
77+ it "queues a job to generate gists" do
78+ expect { DiscourseEvent . trigger ( :topic_hot_scores_updated ) } . to change (
79+ Jobs ::HotTopicsGistBatch . jobs ,
80+ :size ,
81+ ) . by ( 1 )
82+ end
83+ end
6684end
You can’t perform that action at this time.
0 commit comments