Skip to content

Commit 2a3c351

Browse files
authored
Merge pull request #309 from joyofrails/fix/refresh-index
Fix refresh index
2 parents d4f8612 + 71758cf commit 2a3c351

File tree

56 files changed

+345
-314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+345
-314
lines changed

app/jobs/pages/analyze_topics_job.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33

44
module Pages
55
class AnalyzeTopicsJob < ApplicationJob
6+
class Batch < ApplicationJob
7+
queue_as :default
8+
9+
def perform
10+
Page.published.where.missing(:topics).find_each do |page|
11+
Pages::AnalyzeTopicsJob.perform_later(page)
12+
end
13+
end
14+
end
15+
616
queue_as :default
717

818
def perform(page)

app/jobs/pages/batch_analyze_topics_job.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

app/jobs/pages/batch_embedding_job.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

app/jobs/pages/batch_upsert_pages_job.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ class BatchUpsertPagesJob < ApplicationJob
55
def perform(limit: nil)
66
Page.upsert_collection_from_sitepress!(limit: limit)
77

8-
Pages::RefreshSearchIndexJob.perform_later
9-
Pages::BatchAnalyzeTopicsJob.perform_later
10-
Pages::BatchEmbeddingJob.perform_later
8+
Pages::RefreshSearchIndexJob::Batch.perform_later
9+
Pages::AnalyzeTopicsJob::Batch.perform_later
10+
Pages::EmbeddingJob::Batch.perform_later
1111
end
1212
end
1313
end

app/jobs/pages/embedding_job.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
module Pages
22
class EmbeddingJob < ApplicationJob
3+
class Batch < ApplicationJob
4+
queue_as :default
5+
6+
def perform
7+
Page.published.where.missing(:page_embedding).find_each do |page|
8+
Pages::EmbeddingJob.perform_later(page)
9+
end
10+
end
11+
end
12+
313
queue_as :default
414

515
def perform(page)
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
module Pages
22
class RefreshSearchIndexJob < ApplicationJob
3-
def perform
4-
Page.published.find_each(&:update_in_search_index)
3+
class Batch < ApplicationJob
4+
queue_as :default
5+
6+
def perform
7+
Page.published.find_each do |page|
8+
Pages::RefreshSearchIndexJob.perform_later(page)
9+
end
10+
end
11+
end
12+
13+
queue_as :default
14+
15+
def perform(page)
16+
page.update_in_search_index
517
end
618
end
719
end

app/views/share/polls/lazy_page_poll.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,20 @@ def initialize(page, title, question_data = {})
1313
end
1414

1515
def view_template
16-
poll = Poll.generate_for(page, title, question_data) or return
17-
turbo_frame_tag poll, src: share_poll_path(poll), class: "poll joy-border-subtle rounded"
16+
if render?
17+
turbo_frame_tag poll, src: share_poll_path(poll), class: "poll joy-border-subtle rounded"
18+
end
19+
end
20+
21+
private
22+
23+
def render?
24+
!!page && !!poll
25+
end
26+
27+
def poll
28+
return @poll if defined?(@poll)
29+
@poll = Poll.generate_for(page, title, question_data)
1830
end
1931
end
2032
end

lib/generators/article/templates/article_spec.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ RSpec.describe "<%= title %>", type: :system do
44
it "displays the article content" do
55
visit "/articles/<%= article_file_name %>"
66

7-
expect(page).to have_content <%= title %>
7+
expect(document).to have_content <%= title %>
88
end
99
end

spec/jobs/pages/analyze_topics_job_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,30 @@
2828
expect(page.reload.topics.pluck(:name)).to include("Ruby on Rails")
2929
end
3030
end
31+
32+
describe Pages::AnalyzeTopicsJob::Batch do
33+
it "doesn’t blow up" do
34+
allow(SitepressPage).to receive(:render_html).and_return(Faker::HTML.random)
35+
36+
topics = FactoryBot.create_list(:topic, 2)
37+
38+
page_1, page_2, page_3 = Page.upsert_collection_from_sitepress!(limit: 3).each do |page|
39+
page.touch(:published_at)
40+
end
41+
42+
# articles without topics
43+
page_1.update!(topics: [])
44+
page_2.update!(topics: [])
45+
46+
# articles with topics
47+
page_3.update!(topics: topics)
48+
49+
# not articles
50+
FactoryBot.create_list(:page, 3)
51+
52+
expect(Pages::AnalyzeTopicsJob).to receive(:perform_later).exactly(2).times
53+
54+
described_class.perform_now
55+
end
56+
end
3157
end

spec/jobs/pages/batch_analyze_topics_job_spec.rb

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)