Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Skip DetectTranslation jobs for small action posts #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def execute(args)
return if !SiteSetting.translator_enabled

post = Post.find_by(id: args[:post_id])
return unless post
return if post.nil? || post.raw.blank? || post.post_type == Post.types[:small_action]

DistributedMutex.synchronize("detect_translation_#{post.id}") do
"DiscourseTranslator::#{SiteSetting.translator}".constantize.detect(post)
Expand All @@ -155,6 +155,8 @@ def execute(args)

def post_process(post)
return if !SiteSetting.translator_enabled
return if post.raw.blank? || post.post_type == Post.types[:small_action]

Jobs.enqueue(:detect_translation, post_id: post.id)
end
listen_for :post_process
Expand Down
9 changes: 9 additions & 0 deletions spec/jobs/detect_translation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
expect(post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD]).to be_nil
end

it "does not detect translation for small posts" do
SiteSetting.translator_enabled = false

post = Fabricate(:small_action)
Jobs::DetectTranslation.new.execute(post_id: post.id)

expect(post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD]).to be_nil
end

describe "translator enabled" do
before { SiteSetting.translator_enabled = true }

Expand Down