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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#51316] Improve user groups performace.
Pavel Balashou13a3a18a8fca
diff --git a/modules/storages/app/workers/storages/manage_nextcloud_integration_events_job.rb b/modules/storages/app/workers/storages/manage_nextcloud_integration_events_job.rbindex 99247f93a3f..16feb6b2502 100644--- a/modules/storages/app/workers/storages/manage_nextcloud_integration_events_job.rb+++ b/modules/storages/app/workers/storages/manage_nextcloud_integration_events_job.rb@@ -31,17 +31,22 @@ module Storagesinclude ManageNextcloudIntegrationJobMixinDEBOUNCE_TIME = 5.seconds.freeze+ THREAD_KEY = :manage_nextcloud_integration_events_job_debounce_happend_atqueue_with_priority :above_normaldef self.debounce- count = Delayed::Job- .where("handler LIKE ?", "%job_class: #{self}%")- .where(locked_at: nil)- .where('run_at <= ?', DEBOUNCE_TIME.from_now)- .delete_all- Rails.logger.info("deleted: #{count} jobs")- set(wait: DEBOUNCE_TIME).perform_later+ last_debounce_happend_at = Thread.current[THREAD_KEY]+ if last_debounce_happend_at.blank? || Time.current > (last_debounce_happend_at + DEBOUNCE_TIME)+ count = Delayed::Job+ .where("handler LIKE ?", "%job_class: #{self}%")+ .where(locked_at: nil)+ .where('run_at <= ?', DEBOUNCE_TIME.from_now)+ .delete_all+ Rails.logger.info("deleted: #{count} jobs")+ Thread.current[THREAD_KEY] = Time.current+ set(wait: DEBOUNCE_TIME).perform_later+ endenddef performdiff --git a/modules/storages/spec/workers/storages/manage_nextcloud_integration_events_job_spec.rb b/modules/storages/spec/workers/storages/manage_nextcloud_integration_events_job_spec.rbindex 8f87a9295a2..c9b71ed150a 100644--- a/modules/storages/spec/workers/storages/manage_nextcloud_integration_events_job_spec.rb+++ b/modules/storages/spec/workers/storages/manage_nextcloud_integration_events_job_spec.rb@@ -39,7 +39,7 @@ RSpec.describe Storages::ManageNextcloudIntegrationEventsJob, type: :job doenddescribe '.debounce' do- it 'debounces job with 1 minute timeframe' do+ it 'debounces job with 5 seconds timeframe' doActiveJob::Base.disable_test_adapterother_handler = Storages::ManageNextcloudIntegrationCronJob.perform_later.provider_job_id@@ -54,7 +54,7 @@ RSpec.describe Storages::ManageNextcloudIntegrationEventsJob, type: :job doexpect(Delayed::Job.count).to eq(6)- described_class.debounce+ 1000.times { described_class.debounce }expect(Delayed::Job.count).to eq(4)expect(Delayed::Job.pluck(:id)).to include(other_handler,diff --git a/spec/lib/open_project/events_spec.rb b/spec/lib/open_project/events_spec.rbindex 806304e51d0..f07150f0520 100644--- a/spec/lib/open_project/events_spec.rb+++ b/spec/lib/open_project/events_spec.rb@@ -36,6 +36,10 @@ RSpec.describe OpenProject::Events do)end+ before do+ allow(Storages::ManageNextcloudIntegrationEventsJob).to receive(:debounce)+ end+%w[PROJECT_STORAGE_CREATEDPROJECT_STORAGE_UPDATED@@ -48,20 +52,17 @@ RSpec.describe OpenProject::Events dolet(:payload) { {} }it do- expect { subject }.not_to change(enqueued_jobs, :count)+ subject+ expect(Storages::ManageNextcloudIntegrationEventsJob).not_to have_received(:debounce)endend- context 'when payload contains automatic project_folder_mpde' do+ context 'when payload contains automatic project_folder_mode' dolet(:payload) { { project_folder_mode: :automatic } }- it do- expect { subject }.to change(enqueued_jobs, :count).from(0).to(1)- end-it dosubject- expect(enqueued_jobs[0][:job]).to eq(Storages::ManageNextcloudIntegrationEventsJob)+ expect(Storages::ManageNextcloudIntegrationEventsJob).to have_received(:debounce)endit do@@ -90,13 +91,9 @@ RSpec.describe OpenProject::Events dolet(:payload) { {} }- it do- expect { subject }.to change(enqueued_jobs, :count).from(0).to(1)- end-it dosubject- expect(enqueued_jobs[0][:job]).to eq(Storages::ManageNextcloudIntegrationEventsJob)+ expect(Storages::ManageNextcloudIntegrationEventsJob).to have_received(:debounce)endendend@@ -108,20 +105,17 @@ RSpec.describe OpenProject::Events dolet(:payload) { {} }it do- expect { subject }.not_to change(enqueued_jobs, :count)+ subject+ expect(Storages::ManageNextcloudIntegrationEventsJob).not_to have_received(:debounce)endendcontext 'when payload contains storage integration type' dolet(:payload) { { integration_type: 'Storages::Storage' } }- it do- expect { subject }.to change(enqueued_jobs, :count).from(0).to(1)- end-it dosubject- expect(enqueued_jobs[0][:job]).to eq(Storages::ManageNextcloudIntegrationEventsJob)+ expect(Storages::ManageNextcloudIntegrationEventsJob).to have_received(:debounce)endendend@@ -133,20 +127,17 @@ RSpec.describe OpenProject::Events dolet(:payload) { {} }it do- expect { subject }.not_to change(enqueued_jobs, :count)+ subject+ expect(Storages::ManageNextcloudIntegrationEventsJob).not_to have_received(:debounce)endendcontext 'when payload contains some nextcloud related permissions as a diff' dolet(:payload) { { permissions_diff: [:read_files] } }- it do- expect { subject }.to change(enqueued_jobs, :count).from(0).to(1)- end-it dosubject- expect(enqueued_jobs[0][:job]).to eq(Storages::ManageNextcloudIntegrationEventsJob)+ expect(Storages::ManageNextcloudIntegrationEventsJob).to have_received(:debounce)endendend@@ -158,20 +149,17 @@ RSpec.describe OpenProject::Events dolet(:payload) { {} }it do- expect { subject }.not_to change(enqueued_jobs, :count)+ subject+ expect(Storages::ManageNextcloudIntegrationEventsJob).not_to have_received(:debounce)endendcontext 'when payload contains some nextcloud related permissions' dolet(:payload) { { permissions: [:read_files] } }- it do- expect { subject }.to change(enqueued_jobs, :count).from(0).to(1)- end-it dosubject- expect(enqueued_jobs[0][:job]).to eq(Storages::ManageNextcloudIntegrationEventsJob)+ expect(Storages::ManageNextcloudIntegrationEventsJob).to have_received(:debounce)endendend