Remove unused methods _without_delay (#4366) [ci skip]

This commit is contained in:
Araslanov Evgeny 2019-10-16 19:35:49 +05:00 committed by Mac Siri
parent 89af535146
commit 02a75b6efa
12 changed files with 57 additions and 108 deletions

View file

@ -40,8 +40,4 @@ class RateLimitChecker
def ping_admins
RateLimitCheckerJob.perform_later(user.id, action)
end
def ping_admins_without_delay
RateLimitCheckerJob.perform_now(user.id, action)
end
end

View file

@ -346,24 +346,12 @@ class Article < ApplicationRecord
@flare_tag ||= FlareTag.new(self).tag_hash
end
def update_main_image_background_hex_without_delay
return if main_image.blank? || main_image_background_hex_color != "#dddddd"
Articles::UpdateMainImageBackgroundHexJob.perform_now(id)
end
def update_main_image_background_hex
return if main_image.blank? || main_image_background_hex_color != "#dddddd"
Articles::UpdateMainImageBackgroundHexJob.perform_later(id)
end
def detect_human_language_without_delay
return if language.present?
Articles::DetectHumanLanguageJob.perform_now(id)
end
def detect_human_language
return if language.present?

View file

@ -30,11 +30,9 @@ class BadgeAchievement < ApplicationRecord
end
def send_email_notification
BadgeAchievements::SendEmailNotificationJob.perform_later(id) if user.class.name == "User" && user.email.present? && user.email_badge_notifications
end
return unless user.class.name == "User" && user.email.present? && user.email_badge_notifications
def send_email_notification_without_delay
BadgeAchievements::SendEmailNotificationJob.perform_now(id) if user.class.name == "User" && user.email.present? && user.email_badge_notifications
BadgeAchievements::SendEmailNotificationJob.perform_later(id)
end
def award_credits

View file

@ -14,20 +14,13 @@ class Mention < ApplicationRecord
def create_all(notifiable)
Mentions::CreateAllJob.perform_later(notifiable.id, notifiable.class.name)
end
def create_all_without_delay(notifiable)
Mentions::CreateAllJob.perform_now(notifiable.id, notifiable.class.name)
end
end
def send_email_notification
user = User.find(user_id)
Mentions::SendEmailNotificationJob.perform_later(id) if user.email.present? && user.email_mention_notifications
end
return unless user.email.present? && user.email_mention_notifications
def send_email_notification_without_delay
user = User.find(user_id)
Mentions::SendEmailNotificationJob.perform_now(id) if user.email.present? && user.email_mention_notifications
Mentions::SendEmailNotificationJob.perform_later(id)
end
def permission

View file

@ -45,10 +45,6 @@ class Notification < ApplicationRecord
Notifications::NotifiableActionJob.perform_later(notifiable.id, notifiable.class.name, action)
end
def send_to_followers_without_delay(notifiable, action = nil)
Notifications::NotifiableActionJob.perform_now(notifiable.id, notifiable.class.name, action)
end
def send_new_comment_notifications(comment)
return if comment.commentable_type == "PodcastEpisode"
@ -69,13 +65,6 @@ class Notification < ApplicationRecord
# It can be removed after pre-existing jobs are done
alias send_new_badge_notification send_new_badge_achievement_notification
# NOTE: this method is temporary until the transition to ActiveJob is completed
# and all old DelayedJob jobs are processed by the queue workers.
# It can be removed after pre-existing jobs are done
def send_new_badge_notification_without_delay(badge_achievement)
Notifications::NewBadgeAchievementJob.perform_now(badge_achievement.id)
end
def send_reaction_notification(reaction, receiver)
return if reaction.skip_notification_for?(receiver)
@ -92,42 +81,22 @@ class Notification < ApplicationRecord
Notifications::MentionJob.perform_later(mention.id)
end
def send_mention_notification_without_delay(mention)
Notifications::MentionJob.perform_now(mention.id)
end
def send_welcome_notification(receiver_id)
Notifications::WelcomeNotificationJob.perform_later(receiver_id)
end
def send_welcome_notification_without_delay(receiver_id)
Notifications::WelcomeNotificationJob.perform_now(receiver_id)
end
def send_moderation_notification(notifiable)
Notifications::ModerationNotificationJob.perform_later(notifiable.id)
end
def send_moderation_notification_without_delay(notifiable)
Notifications::ModerationNotificationJob.perform_now(notifiable.id)
end
def send_tag_adjustment_notification(tag_adjustment)
Notifications::TagAdjustmentNotificationJob.perform_later(tag_adjustment.id)
end
def send_tag_adjustment_notification_without_delay(tag_adjustment)
Notifications::TagAdjustmentNotificationJob.perform_now(tag_adjustment.id)
end
def send_milestone_notification(type:, article_id:)
Notifications::MilestoneJob.perform_later(type, article_id)
end
def send_milestone_notification_without_delay(type:, article_id:)
Notifications::MilestoneJob.perform_now(type, article_id)
end
def remove_all_by_action(notifiable_ids:, notifiable_type:, action: nil)
return unless %w[Article Comment Mention].include?(notifiable_type) && notifiable_ids.present?
@ -156,10 +125,6 @@ class Notification < ApplicationRecord
Notifications::UpdateJob.perform_later(notifiable.id, notifiable.class.name, action)
end
def update_notifications_without_delay(notifiable, action = nil)
Notifications::UpdateJob.perform_now(notifiable.id, notifiable.class.name, action)
end
private
def user_data(user)

View file

@ -149,7 +149,7 @@ class User < ApplicationRecord
after_save :bust_cache
after_save :subscribe_to_mailchimp_newsletter
after_save :conditionally_resave_articles
after_create :estimate_default_language!
after_create :estimate_default_language
before_create :set_default_language
before_validation :set_username
# make sure usernames are not empty, to be able to use the database unique index
@ -216,14 +216,10 @@ class User < ApplicationRecord
self.remember_created_at ||= Time.now.utc
end
def estimate_default_language!
def estimate_default_language
Users::EstimateDefaultLanguageJob.perform_later(id)
end
def estimate_default_language_without_delay!
Users::EstimateDefaultLanguageJob.perform_now(id)
end
def calculate_score
score = (articles.where(featured: true).size * 100) + comments.sum(:score)
update_column(:score, score)
@ -384,17 +380,8 @@ class User < ApplicationRecord
errors.add(:username, "is taken.") if Organization.find_by(slug: username) || Podcast.find_by(slug: username) || Page.find_by(slug: username)
end
def subscribe_to_mailchimp_newsletter_without_delay
return unless email.present? && email.include?("@")
return if saved_changes["unconfirmed_email"] && saved_changes["confirmation_sent_at"]
Users::SubscribeToMailchimpNewsletterJob.perform_now(id)
end
def subscribe_to_mailchimp_newsletter
return unless email.present? && email.include?("@")
return if saved_changes["unconfirmed_email"] && saved_changes["confirmation_sent_at"]
Users::SubscribeToMailchimpNewsletterJob.perform_later(id)

View file

@ -388,7 +388,7 @@ RSpec.describe Notification, type: :model do
context "when there are article notifications to update" do
before do
user2.follow(user)
described_class.send_to_followers_without_delay(article, "Published")
perform_enqueued_jobs { described_class.send_to_followers(article, "Published") }
end
it "updates the notification with the new article title" do
@ -447,14 +447,6 @@ RSpec.describe Notification, type: :model do
end
end
describe "#send_new_badge_notification_without_delay (deprecated)" do
it "creates a notification" do
expect do
described_class.send_new_badge_notification_without_delay(badge_achievement)
end.to change(described_class, :count).by(1)
end
end
describe "#remove_all" do
let(:mention) { create(:mention, user_id: user.id, mentionable_id: comment.id, mentionable_type: "Comment") }
let(:comment) { create(:comment, user_id: user.id, commentable_id: article.id) }

View file

@ -431,7 +431,7 @@ RSpec.describe User, type: :model do
it "estimates default language to be nil" do
perform_enqueued_jobs do
user.estimate_default_language!
user.estimate_default_language
end
expect(user.reload.estimated_default_language).to eq(nil)
end
@ -439,7 +439,7 @@ RSpec.describe User, type: :model do
it "estimates default language to be japan with jp email" do
perform_enqueued_jobs do
user.update_column(:email, "ben@hello.jp")
user.estimate_default_language!
user.estimate_default_language
end
expect(user.reload.estimated_default_language).to eq("ja")
end
@ -447,7 +447,7 @@ RSpec.describe User, type: :model do
it "estimates default language based on ID dump" do
perform_enqueued_jobs do
new_user = user_from_authorization_service(:twitter, nil, "navbar_basic")
new_user.estimate_default_language!
new_user.estimate_default_language
expect(user.reload.estimated_default_language).to eq(nil)
end
end
@ -455,7 +455,7 @@ RSpec.describe User, type: :model do
it "returns proper preferred_languages_array" do
perform_enqueued_jobs do
user.update_column(:email, "ben@hello.jp")
user.estimate_default_language!
user.estimate_default_language
end
expect(user.reload.preferred_languages_array).to include("ja")
end
@ -586,10 +586,6 @@ RSpec.describe User, type: :model do
expect(user.decorate.config_body_class).to eq("default default-article-body pro-status-#{user.pro?} trusted-status-#{user.trusted}")
end
it "inserts into mailchimp" do
expect(user.subscribe_to_mailchimp_newsletter_without_delay).to eq true
end
it "does not allow to change to username that is taken" do
user.username = second_user.username
expect(user).not_to be_valid
@ -725,4 +721,14 @@ RSpec.describe User, type: :model do
expect(user.has_enough_credits?(1)).to be(true)
end
end
describe "#subscribe_to_mailchimp_newsletter" do
let(:user2) { create :user }
it "schedules the job" do
expect do
user2.subscribe_to_mailchimp_newsletter
end.to have_enqueued_job(Users::SubscribeToMailchimpNewsletterJob).exactly(:once).with(user2.id)
end
end
end

View file

@ -94,7 +94,11 @@ RSpec.describe "ArticlesUpdate", type: :request do
it "removes all published notifications if unpublished" do
user2.follow(user)
Notification.send_to_followers_without_delay(article, "Published")
perform_enqueued_jobs do
Notification.send_to_followers(article, "Published")
end
expect(article.notifications.size).to eq 1
put "/articles/#{article.id}", params: {
article: { body_markdown: article.body_markdown.gsub("published: true", "published: false") }
}

View file

@ -29,7 +29,9 @@ RSpec.describe "Internal::Users", type: :request do
create(:reaction, reactable: comment2, reactable_type: "Comment", user: user2)
# create user3 reaction to offending article
create(:reaction, reactable: article, reactable_type: "Article", user: user3, category: "like")
Mention.create_all_without_delay(comment2)
perform_enqueued_jobs do
Mention.create_all(comment2)
end
Delayed::Worker.new(quiet: true).work_off
end
@ -170,7 +172,9 @@ RSpec.describe "Internal::Users", type: :request do
user_id: user2.id,
commentable_id: article2.id,
)
Mention.create_all_without_delay(comment)
perform_enqueued_jobs do
Mention.create_all(comment)
end
end
def create_mutual_follows

View file

@ -216,7 +216,9 @@ RSpec.describe "NotificationsIndex", type: :request do
before do
user.add_role :trusted
sign_in user
Notification.send_moderation_notification_without_delay(comment)
perform_enqueued_jobs do
Notification.send_moderation_notification(comment)
end
get "/notifications"
end
@ -240,7 +242,9 @@ RSpec.describe "NotificationsIndex", type: :request do
before do
sign_in user
Notification.send_moderation_notification_without_delay(comment)
perform_enqueued_jobs do
Notification.send_moderation_notification(comment)
end
get "/notifications"
end
@ -266,7 +270,9 @@ RSpec.describe "NotificationsIndex", type: :request do
user.add_role :trusted
user.update(mod_roundrobin_notifications: false)
sign_in user
Notification.send_moderation_notification_without_delay(comment)
perform_enqueued_jobs do
Notification.send_moderation_notification(comment)
end
get "/notifications"
end
@ -290,7 +296,9 @@ RSpec.describe "NotificationsIndex", type: :request do
it "renders the welcome notification" do
broadcast = create(:broadcast, :onboarding)
Notification.send_welcome_notification_without_delay(user.id)
perform_enqueued_jobs do
Notification.send_welcome_notification(user.id)
end
get "/notifications"
expect(response.body).to include broadcast.processed_html
end
@ -339,8 +347,10 @@ RSpec.describe "NotificationsIndex", type: :request do
before do
comment
Mention.create_all_without_delay(comment)
Notification.send_mention_notification_without_delay(Mention.first)
perform_enqueued_jobs do
Mention.create_all(comment)
Notification.send_mention_notification(Mention.first)
end
sign_in user
get "/notifications"
end
@ -360,7 +370,9 @@ RSpec.describe "NotificationsIndex", type: :request do
before do
user2.follow(user)
Notification.send_to_followers_without_delay(article, "Published")
perform_enqueued_jobs do
Notification.send_to_followers(article, "Published")
end
sign_in user2
get "/notifications"
end
@ -399,7 +411,9 @@ RSpec.describe "NotificationsIndex", type: :request do
before do
user2.follow(user)
Notification.send_to_followers_without_delay(article, "Published")
perform_enqueued_jobs do
Notification.send_to_followers(article, "Published")
end
sign_in admin
end

View file

@ -18,7 +18,9 @@ RSpec.describe Notifications::TagAdjustmentNotification::Send do
end
it "notifies the author of the article" do
Notification.send_tag_adjustment_notification_without_delay(tag_adjustment)
perform_enqueued_jobs do
Notification.send_tag_adjustment_notification(tag_adjustment)
end
expect(Notification.first.user_id).to eq user2.id
end