Skip to content

Commit

Permalink
Maintenance: Update dependency rubocop-rails to v2.25.0
Browse files Browse the repository at this point in the history
  • Loading branch information
renovatebot authored and mantas committed May 22, 2024
1 parent a92e8fb commit da77305
Show file tree
Hide file tree
Showing 24 changed files with 197 additions and 164 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ GEM
rspec-expectations (~> 3.12)
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
racc (1.7.3)
racc (1.8.0)
rack (2.2.9)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
Expand Down Expand Up @@ -514,7 +514,7 @@ GEM
ffi (~> 1.0)
rchardet (1.8.0)
redis (4.8.1)
regexp_parser (2.9.0)
regexp_parser (2.9.2)
rexml (3.2.8)
strscan (>= 3.0.9)
rotp (6.3.0)
Expand Down Expand Up @@ -567,7 +567,7 @@ GEM
rubocop-performance (1.21.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.24.1)
rubocop-rails (2.25.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/active_job_lock_cleanup_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class ActiveJobLockCleanupJob < ApplicationJob
include HasActiveJobLock

def perform(diff = 1.day)
::ActiveJobLock.where('created_at < ?', Time.zone.now - diff).destroy_all
::ActiveJobLock.where(created_at: ...diff.ago).destroy_all
end
end
3 changes: 1 addition & 2 deletions app/jobs/taskbar_cleanup_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ class TaskbarCleanupJob < ApplicationJob

def perform
Taskbar
.where(app: :mobile)
.where('last_contact < ?', LAST_CONTACT_THRESHOLD.ago)
.where(app: :mobile, last_contact: ...LAST_CONTACT_THRESHOLD.ago)
.destroy_all
end
end
11 changes: 8 additions & 3 deletions app/jobs/upload_cache_cleanup_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ def perform
taskbar_form_ids = Taskbar.with_form_id.filter_map(&:persisted_form_id)
return if store_object_id.blank?

Store.where(store_object_id: store_object_id).where('created_at < ?', 1.month.ago).where.not(o_id: taskbar_form_ids).find_each do |store|
Store.remove_item(store.id)
end
Store
.where(store_object_id: store_object_id, created_at: ...1.month.ago)
.where.not(o_id: taskbar_form_ids)
.in_batches do |batch|
batch
.pluck(:id)
.each { |elem| Store.remove_item(elem) }
end
end

private
Expand Down
4 changes: 3 additions & 1 deletion app/models/activity_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def self.list(user, limit)
=end

def self.cleanup(diff = 3.months)
ActivityStream.where('created_at < ?', Time.zone.now - diff).delete_all
where(created_at: ...diff.ago)
.delete_all

true
end

Expand Down
38 changes: 21 additions & 17 deletions app/models/chat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,9 @@ def self.broadcast_customer_state_update(chat_id)
=end

def self.cleanup(diff = 12.months)
Chat::Session.where(state: 'closed').where('updated_at < ?', Time.zone.now - diff).each do |chat_session|
Chat::Message.where(chat_session_id: chat_session.id).delete_all
chat_session.destroy
end
Chat::Session
.where(state: 'closed', updated_at: ...diff.ago)
.each(&:destroy)

true
end
Expand All @@ -578,20 +577,25 @@ def self.cleanup(diff = 12.months)
=end

def self.cleanup_close(diff = 5.minutes)
Chat::Session.where.not(state: 'closed').where('updated_at < ?', Time.zone.now - diff).each do |chat_session|
next if chat_session.recipients_active?
Chat::Session
.where.not(state: 'closed')
.where(updated_at: ...diff.ago)
.each do |chat_session|
next if chat_session.recipients_active?

chat_session.state = 'closed'
chat_session.save

message = {
event: 'chat_session_closed',
data: {
session_id: chat_session.session_id,
realname: 'System',
},
}
chat_session.send_to_recipients(message)
end

chat_session.state = 'closed'
chat_session.save
message = {
event: 'chat_session_closed',
data: {
session_id: chat_session.session_id,
realname: 'System',
},
}
chat_session.send_to_recipients(message)
end
true
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/chat/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Chat::Session < ApplicationModel
include Chat::Session::Assets

# rubocop:disable Rails/InverseOf
has_many :messages, class_name: 'Chat::Message', foreign_key: 'chat_session_id', dependent: :destroy
has_many :messages, class_name: 'Chat::Message', foreign_key: 'chat_session_id', dependent: :delete_all
belongs_to :user, class_name: 'User', optional: true
belongs_to :chat, class_name: 'Chat'
# rubocop:enable Rails/InverseOf
Expand Down
4 changes: 3 additions & 1 deletion app/models/cti/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ def push_caller_list_update
=end

def self.cleanup(diff = 12.months)
Cti::Log.where('created_at < ?', Time.zone.now - diff).delete_all
where(created_at: ...diff.ago)
.delete_all

true
end

Expand Down
4 changes: 3 additions & 1 deletion app/models/data_privacy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def perform
end

def self.cleanup(diff = 12.months)
where('created_at < ?', diff.ago).destroy_all
where(created_at: ...diff.ago)
.destroy_all

true
end

Expand Down
4 changes: 3 additions & 1 deletion app/models/http_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class HttpLog < ApplicationModel
=end

def self.cleanup(diff = 1.month)
HttpLog.where('created_at < ?', Time.zone.now - diff).delete_all
where(created_at: ...diff.ago)
.delete_all

true
end

Expand Down
19 changes: 10 additions & 9 deletions app/models/import_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,16 @@ def self.cleanup_import_jobs(after)
# we need to exclude jobs that were updated at or since we started
# cleaning up (via the #reschedule? call) because they might
# were started `.delay`-ed and are flagged for restart
ImportJob.running.where('updated_at < ?', after).each do |job|

job.update!(
finished_at: after,
result: {
error: error
}
)
end
running
.where(updated_at: ...after)
.each do |job|
job.update!(
finished_at: after,
result: {
error: error
}
)
end
end
end
end
6 changes: 2 additions & 4 deletions app/models/online_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,11 @@ def self.list_by_object(object_name, o_id)
def self.cleanup(max_age = 9.months.ago, max_own_seen = 10.minutes.ago, max_auto_seen = 8.hours.ago)
affected_user_ids = []

OnlineNotification
.where('created_at < ?', max_age)
where(created_at: ...max_age)
.tap { |relation| affected_user_ids |= relation.distinct.pluck(:user_id) }
.delete_all

OnlineNotification
.where(seen: true)
where(seen: true)
.where('(user_id = updated_by_id AND updated_at < :max_own_seen) OR (user_id != updated_by_id AND updated_at < :max_auto_seen)',
max_own_seen:, max_auto_seen:)
.tap { |relation| affected_user_ids |= relation.distinct.pluck(:user_id) }
Expand Down
4 changes: 3 additions & 1 deletion app/models/recent_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def self.access(object, o_id, user)
=end

def self.cleanup(diff = 3.months)
RecentView.where('created_at < ?', Time.zone.now - diff).delete_all
where(created_at: ...diff.ago)
.delete_all

true
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def self.load(force = false)
base_query = Setting.reorder(:id)

settings_query = if @@last_changed_at && @@current.present?
base_query.where('updated_at >= ?', @@last_changed_at)
base_query.where(updated_at: @@last_changed_at..)
else
base_query
end
Expand Down
4 changes: 3 additions & 1 deletion app/models/stats_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def self.sync(params)
=end

def self.cleanup(diff = 12.months)
StatsStore.where('updated_at < ?', Time.zone.now - diff).delete_all
where(updated_at: ...diff.ago)
.delete_all

true
end

Expand Down
97 changes: 47 additions & 50 deletions app/models/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,16 @@ def self.process_pending
next_state_map[state.id] = state.next_state_id
end

tickets = where(state_id: next_state_map.keys)
.where('pending_time <= ?', Time.zone.now)

tickets.find_each(batch_size: 500) do |ticket|
Transaction.execute do
ticket.state_id = next_state_map[ticket.state_id]
ticket.updated_at = Time.zone.now
ticket.updated_by_id = 1
ticket.save!
where(state_id: next_state_map.keys, pending_time: ..Time.current)
.find_each(batch_size: 500) do |ticket|
Transaction.execute do
ticket.state_id = next_state_map[ticket.state_id]
ticket.updated_at = Time.zone.now
ticket.updated_by_id = 1
ticket.save!
end
result.push ticket
end
result.push ticket
end
end

# process pending reminder tickets
Expand All @@ -159,28 +157,26 @@ def self.process_pending
reminder_state_map[state.id] = state.next_state_id
end

tickets = where(state_id: reminder_state_map.keys)
.where('pending_time <= ?', Time.zone.now)

tickets.find_each(batch_size: 500) do |ticket|
where(state_id: reminder_state_map.keys, pending_time: ..Time.current)
.find_each(batch_size: 500) do |ticket|

article_id = nil
article = Ticket::Article.last_customer_agent_article(ticket.id)
if article
article_id = article.id
end
article_id = nil
article = Ticket::Article.last_customer_agent_article(ticket.id)
if article
article_id = article.id
end

# send notification
TransactionJob.perform_now(
object: 'Ticket',
type: 'reminder_reached',
object_id: ticket.id,
article_id: article_id,
user_id: 1,
)
# send notification
TransactionJob.perform_now(
object: 'Ticket',
type: 'reminder_reached',
object_id: ticket.id,
article_id: article_id,
user_id: 1,
)

result.push ticket
end
result.push ticket
end
end

result
Expand Down Expand Up @@ -227,37 +223,38 @@ def self.process_escalation
result = []

# fetch all escalated and soon to be escalating tickets
where('escalation_at <= ?', 15.minutes.from_now).find_each(batch_size: 500) do |ticket|
where(escalation_at: ..15.minutes.from_now)
.find_each(batch_size: 500) do |ticket|
article_id = nil
article = Ticket::Article.last_customer_agent_article(ticket.id)
if article
article_id = article.id
end

article_id = nil
article = Ticket::Article.last_customer_agent_article(ticket.id)
if article
article_id = article.id
end
# send escalation
if ticket.escalation_at < Time.zone.now
TransactionJob.perform_now(
object: 'Ticket',
type: 'escalation',
object_id: ticket.id,
article_id: article_id,
user_id: 1,
)
result.push ticket
next
end

# send escalation
if ticket.escalation_at < Time.zone.now
# check if warning needs to be sent
TransactionJob.perform_now(
object: 'Ticket',
type: 'escalation',
type: 'escalation_warning',
object_id: ticket.id,
article_id: article_id,
user_id: 1,
)
result.push ticket
next
end

# check if warning needs to be sent
TransactionJob.perform_now(
object: 'Ticket',
type: 'escalation_warning',
object_id: ticket.id,
article_id: article_id,
user_id: 1,
)
result.push ticket
end
result
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.cleanup_delayed_jobs(after)
end

private_class_method def self.scope(after)
::Delayed::Job.where('updated_at < ?', after).where.not(locked_at: nil)
::Delayed::Job.where(updated_at: ...after).where.not(locked_at: nil)
end

def initialize(job)
Expand Down
2 changes: 1 addition & 1 deletion lib/monitoring_helper/amount_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def created_at_threshold
end

def ticket_count
@ticket_count ||= Ticket.where('created_at >= ?', created_at_threshold).count
@ticket_count ||= Ticket.where(created_at: created_at_threshold..).count
end

def check_single_row(row, value)
Expand Down
Loading

1 comment on commit da77305

@mgruner
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit applies many suggested changes from the improved rubocop-rails policies.

Specifically, instead of passing in raw SQL to ActiveRecord queries, it is now possible to use the Ruby Range operators / object to specify date ranges. See also https://devdocs.io/ruby~3.2/range.

Please sign in to comment.