FIX: many missing topics when categories excluded (#585)

We were forgetting about the NULL parent_category_id handling in
our check for sub categories
This commit is contained in:
Sam 2024-04-23 08:53:51 +10:00 committed by GitHub
parent 595cde0fd6
commit 4d8b7742da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -45,7 +45,8 @@ module DiscourseAi
@posts = @posts.where("categories.id IN (?)", @category_ids) if @category_ids.present?
@posts =
@posts.where(
"categories.id NOT IN (:ids) AND parent_category_id NOT IN (:ids)",
"categories.id NOT IN (:ids) AND
(parent_category_id NOT IN (:ids) OR parent_category_id IS NULL)",
ids: exclude_category_ids,
) if exclude_category_ids.present?

View File

@ -58,6 +58,10 @@ module DiscourseAi
post_in_subcategory =
Fabricate(:post, raw: "I am in a subcategory abcd", topic: topic_in_subcategory)
other_category = Fabricate(:category)
topic2 = Fabricate(:topic, category: other_category)
post2 = Fabricate(:post, raw: "I am in another category 123", topic: topic2)
freeze_time
DiscourseAi::Completions::Llm.with_prepared_responses(["magical report"]) do
@ -85,6 +89,7 @@ module DiscourseAi
expect(debugging).not_to include(post_in_category.raw)
expect(debugging).not_to include(post_in_subcategory.raw)
expect(debugging).to include(post2.raw)
end
it "can suppress notifications by remapping content" do