Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Avoid running oauth cleanup job after every authentication (#9241)

Oliver Güntherfa3481523bf0
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index b2b81891588..9d6570d9069 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -53,9 +53,6 @@ class Attachment < ApplicationRecord
after_commit :extract_fulltext, on: :create
- after_create :schedule_cleanup_uncontainered_job,
- unless: :containered?
-
##
# Returns an URL if the attachment is stored in an external (fog) attachment storage
# or nil otherwise.
@@ -292,10 +289,6 @@ class Attachment < ApplicationRecord
private
- def schedule_cleanup_uncontainered_job
- Attachments::CleanupUncontaineredJob.perform_later
- end
-
def filesize_below_allowed_maximum
if filesize > Setting.attachment_max_size.to_i.kilobytes
errors.add(:file, :file_too_large, count: Setting.attachment_max_size.to_i.kilobytes)
diff --git a/app/workers/attachments/cleanup_uncontainered_job.rb b/app/workers/attachments/cleanup_uncontainered_job.rb
index b3886639284..415273dfdd3 100644
--- a/app/workers/attachments/cleanup_uncontainered_job.rb
+++ b/app/workers/attachments/cleanup_uncontainered_job.rb
@@ -28,9 +28,12 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Attachments::CleanupUncontaineredJob < ApplicationJob
+class Attachments::CleanupUncontaineredJob < ::Cron::CronJob
queue_with_priority :low
+ # runs at 10:03 pm
+ self.cron_expression = '03 22 * * *'
+
def perform
Attachment
.where(container: nil)
diff --git a/app/workers/oauth/cleanup_job.rb b/app/workers/oauth/cleanup_job.rb
index 47cef9f8cc4..50675837616 100644
--- a/app/workers/oauth/cleanup_job.rb
+++ b/app/workers/oauth/cleanup_job.rb
@@ -29,9 +29,13 @@
#++
module OAuth
- class CleanupJob < ::ApplicationJob
+ class CleanupJob < ::Cron::CronJob
include ::RakeJob
+ # runs at 1:52 nightly
+ self.cron_expression = '52 1 * * *'
+
+
queue_with_priority :low
def perform
diff --git a/config/initializers/cronjobs.rb b/config/initializers/cronjobs.rb
index 00e14d88fcc..116d397a2b3 100644
--- a/config/initializers/cronjobs.rb
+++ b/config/initializers/cronjobs.rb
@@ -4,6 +4,8 @@ OpenProject::Application.configure do |application|
application.config.to_prepare do
::Cron::CronJob.register! ::Cron::ClearOldSessionsJob,
::Cron::ClearTmpCacheJob,
- ::Cron::ClearUploadedFilesJob
+ ::Cron::ClearUploadedFilesJob,
+ ::OAuth::CleanupJob,
+ ::Attachments::CleanupUncontaineredJob
end
end
diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb
index 7c8bd6f3537..12819f09402 100644
--- a/config/initializers/doorkeeper.rb
+++ b/config/initializers/doorkeeper.rb
@@ -183,10 +183,6 @@ Doorkeeper.configure do
# Rails.logger.info(params.inspect)
# end
#
- after_successful_authorization do |_controller|
- # Schedule a cleanup job to clean out over-TTL tokens and grants
- ::OAuth::CleanupJob.perform_later
- end
# Under some circumstances you might want to have applications auto-approved,
# so that the user skips the authorization step.
diff --git a/spec/models/attachment_spec.rb b/spec/models/attachment_spec.rb
index 5959c406409..9d9d49611fa 100644
--- a/spec/models/attachment_spec.rb
+++ b/spec/models/attachment_spec.rb
@@ -174,21 +174,6 @@ describe Attachment, type: :model do
expect(attachment.digest)
.to eql Digest::MD5.file(file.path).hexdigest
end
-
- it 'adds no cleanup job' do
- expect(Attachments::CleanupUncontaineredJob).not_to receive(:perform_later)
-
- attachment.save!
- end
-
- context 'with an unclaimed attachment' do
- let(:container) { nil }
-
- it 'adds a cleanup job' do
- expect(Attachments::CleanupUncontaineredJob).to receive(:perform_later)
- attachment.save!
- end
- end
end
describe 'two attachments with same file name' do