mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-08-04 04:03:29 +00:00
TopicQuery already provides a lot of safeguards and options for filtering topic, and enforcing permissions. It makes sense to rely on it as other plugins like discourse-assign do. As a bonus, we now have access to the current_user while serializing these topics, so users will see things like unread posts count just like we do for the lists.
42 lines
1.4 KiB
Ruby
42 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
describe DiscourseAi::Embeddings::SemanticRelated do
|
|
fab!(:target) { Fabricate(:topic) }
|
|
fab!(:normal_topic_1) { Fabricate(:topic) }
|
|
fab!(:normal_topic_2) { Fabricate(:topic) }
|
|
fab!(:normal_topic_3) { Fabricate(:topic) }
|
|
fab!(:unlisted_topic) { Fabricate(:topic, visible: false) }
|
|
fab!(:private_topic) { Fabricate(:private_message_topic) }
|
|
fab!(:secured_category) { Fabricate(:category, read_restricted: true) }
|
|
fab!(:secured_category_topic) { Fabricate(:topic, category: secured_category) }
|
|
fab!(:closed_topic) { Fabricate(:topic, closed: true) }
|
|
|
|
before { SiteSetting.ai_embeddings_semantic_related_topics_enabled = true }
|
|
|
|
describe "#related_topic_ids_for" do
|
|
context "when embeddings do not exist" do
|
|
let (:topic) do
|
|
Fabricate(:topic).tap { described_class.clear_cache_for(target) }
|
|
end
|
|
|
|
it "queues job only once per 15 minutes" do
|
|
results = nil
|
|
|
|
expect_enqueued_with(job: :generate_embeddings, args: { topic_id: topic.id }) do
|
|
results = described_class.related_topic_ids_for(topic)
|
|
end
|
|
|
|
expect(results).to eq([])
|
|
|
|
expect_not_enqueued_with(job: :generate_embeddings, args: { topic_id: topic.id }) do
|
|
results = described_class.related_topic_ids_for(topic)
|
|
end
|
|
|
|
expect(results).to eq([])
|
|
end
|
|
end
|
|
end
|
|
end
|