Skip to content

Commit 2397335

Browse files
authored
DEV: Follow up after #294 (#300)
* DEV: Follow up after #294 * Also prevent find errors by using find_by
1 parent 247b890 commit 2397335

File tree

9 files changed

+7
-543
lines changed

9 files changed

+7
-543
lines changed

app/jobs/regular/detect_translate_post.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def execute(args)
77
return unless SiteSetting.experimental_content_translation
88
return if args[:post_id].blank?
99

10-
post = Post.find(args[:post_id])
10+
post = Post.find_by(id: args[:post_id])
1111
return if post.blank? || post.raw.blank? || post.deleted_at.present? || post.user_id <= 0
1212

1313
detected_locale = DiscourseTranslator::PostLocaleDetector.detect_locale(post)

app/jobs/regular/detect_translate_topic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def execute(args)
77
return unless SiteSetting.experimental_content_translation
88
return if args[:topic_id].blank?
99

10-
topic = Topic.find(args[:topic_id])
10+
topic = Topic.find_by(id: args[:topic_id])
1111
if topic.blank? || topic.title.blank? || topic.deleted_at.present? || topic.user_id <= 0
1212
return
1313
end

app/jobs/regular/translate_translatable.rb

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

app/jobs/scheduled/automatic_translation_backfill.rb

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

lib/discourse_translator/automatic_translations.rb

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,22 @@ module DiscourseTranslator
44
class AutomaticTranslations
55
def inject(plugin)
66
plugin.on(:post_process_cooked) do |_, post|
7-
if translatable?(post)
8-
Jobs.enqueue(:translate_translatable, type: "Post", translatable_id: post.id)
9-
end
10-
117
if SiteSetting.experimental_content_localization
128
Jobs.enqueue(:detect_translate_post, post_id: post.id)
139
end
1410
end
1511

1612
plugin.on(:topic_created) do |topic|
17-
if translatable?(topic)
18-
Jobs.enqueue(:translate_translatable, type: "Topic", translatable_id: topic.id)
19-
end
20-
2113
if SiteSetting.experimental_content_localization
2214
Jobs.enqueue(:detect_translate_topic, topic_id: topic.id)
2315
end
2416
end
2517

26-
plugin.on(:topic_edited) do |topic|
27-
if translatable?(topic)
28-
Jobs.enqueue(:translate_translatable, type: "Topic", translatable_id: topic.id)
29-
end
30-
end
31-
3218
plugin.on(:post_edited) do |post, topic_changed|
3319
if SiteSetting.experimental_content_localization && topic_changed
3420
Jobs.enqueue(:detect_translate_topic, topic_id: post.topic_id)
3521
end
3622
end
3723
end
38-
39-
def translatable?(content)
40-
return false if SiteSetting.automatic_translation_target_languages.blank?
41-
return false if content.user_id <= 0
42-
return false if SiteSetting.automatic_translation_backfill_rate <= 0
43-
return true unless SiteSetting.automatic_translation_backfill_limit_to_public_content
44-
45-
public_categories = Category.where(read_restricted: false).pluck(:id)
46-
47-
if content.is_a?(Post)
48-
public_categories.include?(content.topic.category_id)
49-
elsif content.is_a?(Topic)
50-
public_categories.include?(content.category_id)
51-
else
52-
false
53-
end
54-
end
5524
end
5625
end

0 commit comments

Comments
 (0)