DEV: Fix SemanticRelated module load error (#419)
Followup 2636efcd1b
,
whenever ruby code was changed locally this would break
module loading, giving an "uninitialized constant
DiscourseAi::Embeddings::EntryPoint::SemanticRelated" error.
This commit is contained in:
parent
5c9b570562
commit
37b957dbbb
|
@ -15,23 +15,23 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @list.each_with_index do |t,i| %>
|
<% @list.each_with_index do |topic, idx| %>
|
||||||
<tr class="topic-list-item">
|
<tr class="topic-list-item" id="topic-list-item-<%= topic.id %>">
|
||||||
<td class="main-link" itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
|
<td class="main-link" itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
|
||||||
<meta itemprop='position' content='<%= i + 1 %>'>
|
<meta itemprop='position' content='<%= idx + 1 %>'>
|
||||||
<span class="link-top-line">
|
<span class="link-top-line">
|
||||||
<a itemprop='url' href='<%= t.url %>' class='title raw-link raw-topic-link'><%= t.title %></a>
|
<a itemprop='url' href='<%= topic.url %>' class='title raw-link raw-topic-link'><%= topic.title %></a>
|
||||||
</span>
|
</span>
|
||||||
<div class="link-bottom-line">
|
<div class="link-bottom-line">
|
||||||
<% if (!@category || @category.has_children?) && t.category && !t.category.uncategorized? %>
|
<% if (!@category || @category.has_children?) && topic.category && !topic.category.uncategorized? %>
|
||||||
<a href='<%= t.category.url %>' class='badge-wrapper bullet'>
|
<a href='<%= topic.category.url %>' class='badge-wrapper bullet'>
|
||||||
<span class='badge-category-bg' style='background-color: #<%= t.category.color %>'></span>
|
<span class='badge-category-bg' style='background-color: #<%= topic.category.color %>'></span>
|
||||||
<span class='badge-category clear-badge'>
|
<span class='badge-category clear-badge'>
|
||||||
<span class='category-name'><%= t.category.name %></span>
|
<span class='category-name'><%= topic.category.name %></span>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if tags = t.visible_tags(guardian) %>
|
<% if tags = topic.visible_tags(guardian) %>
|
||||||
<div class="discourse-tags">
|
<div class="discourse-tags">
|
||||||
<% tags.each_with_index do |tag, index| %>
|
<% tags.each_with_index do |tag, index| %>
|
||||||
<a href='<%= tag.full_url %>' class='discourse-tag'><%= tag.name %></a>
|
<a href='<%= tag.full_url %>' class='discourse-tag'><%= tag.name %></a>
|
||||||
|
@ -42,13 +42,13 @@
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="replies">
|
<td class="replies">
|
||||||
<span class='posts' title='<%= t 'posts' %>'><%= t.posts_count - 1 %></span>
|
<span class='posts' title='<%= t 'posts' %>'><%= topic.posts_count - 1 %></span>
|
||||||
</td>
|
</td>
|
||||||
<td class="views">
|
<td class="views">
|
||||||
<span class='views' title='<%= t 'views' %>'><%= t.views %></span>
|
<span class='views' title='<%= t 'views' %>'><%= topic.views %></span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= I18n.l(t.last_posted_at || t.created_at, format: :date_only) %>
|
<%= I18n.l(topic.last_posted_at || topic.created_at, format: :date_only) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -38,7 +38,7 @@ module DiscourseAi
|
||||||
end
|
end
|
||||||
|
|
||||||
plugin.register_html_builder("server:topic-show-after-posts-crawler") do |controller|
|
plugin.register_html_builder("server:topic-show-after-posts-crawler") do |controller|
|
||||||
SemanticRelated.related_topics_for_crawler(controller)
|
::DiscourseAi::Embeddings::SemanticRelated.related_topics_for_crawler(controller)
|
||||||
end
|
end
|
||||||
|
|
||||||
# embeddings generation.
|
# embeddings generation.
|
||||||
|
|
|
@ -12,15 +12,15 @@ describe ::TopicsController do
|
||||||
before do
|
before do
|
||||||
SiteSetting.ai_embeddings_semantic_related_topics_enabled = true
|
SiteSetting.ai_embeddings_semantic_related_topics_enabled = true
|
||||||
SiteSetting.ai_embeddings_semantic_related_topics = 2
|
SiteSetting.ai_embeddings_semantic_related_topics = 2
|
||||||
end
|
|
||||||
|
|
||||||
context "when a user is logged on" do
|
|
||||||
it "includes related topics in payload when configured" do
|
|
||||||
DiscourseAi::Embeddings::SemanticRelated
|
DiscourseAi::Embeddings::SemanticRelated
|
||||||
.any_instance
|
.any_instance
|
||||||
.stubs(:related_topic_ids_for)
|
.stubs(:related_topic_ids_for)
|
||||||
.returns([topic1.id, topic2.id, topic3.id])
|
.returns([topic1.id, topic2.id, topic3.id])
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when a user is logged on" do
|
||||||
|
it "includes related topics in payload when configured" do
|
||||||
get("#{topic.relative_url}.json")
|
get("#{topic.relative_url}.json")
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
json = response.parsed_body
|
json = response.parsed_body
|
||||||
|
@ -37,4 +37,18 @@ describe ::TopicsController do
|
||||||
expect(json["related_topics"].length).to eq(2)
|
expect(json["related_topics"].length).to eq(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "crawler" do
|
||||||
|
let(:crawler_user_agent) do
|
||||||
|
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders related topics in the crawler view" do
|
||||||
|
get topic.relative_url, env: { "HTTP_USER_AGENT" => crawler_user_agent }
|
||||||
|
body = response.body
|
||||||
|
expect(body).to have_tag(:div, with: { id: "related-topics" })
|
||||||
|
expect(body).to have_tag(:tr, with: { id: "topic-list-item-#{topic1.id}" })
|
||||||
|
expect(body).to have_tag(:tr, with: { id: "topic-list-item-#{topic2.id}" })
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue