Skip to content

Commit

Permalink
Enqueue only jobs that are relevant to the events
Browse files Browse the repository at this point in the history
  • Loading branch information
mereghost committed Jun 26, 2024
1 parent a1abed1 commit c70486b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions modules/storages/lib/open_project/storages/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,25 @@ def self.permissions
[
OpenProject::Events::MEMBER_CREATED,
OpenProject::Events::MEMBER_UPDATED,
OpenProject::Events::MEMBER_DESTROYED,
OpenProject::Events::PROJECT_UPDATED,
OpenProject::Events::PROJECT_RENAMED,
OpenProject::Events::PROJECT_ARCHIVED,
OpenProject::Events::PROJECT_UNARCHIVED
OpenProject::Events::MEMBER_DESTROYED
].each do |event|
OpenProject::Notifications.subscribe(event) do |_payload|
::Storages::ManageStorageIntegrationsJob.debounce
Storages::Storage.joins(project_storages: :project)
.where(project_storages: { project_id: payload[:member].project_id }).find_each do |storage|
::Storages::AutomaticallyManagedStorageSyncJob.debounce(storage)
end
end
end

[OpenProject::Events::PROJECT_UPDATED,
OpenProject::Events::PROJECT_RENAMED,
OpenProject::Events::PROJECT_ARCHIVED,
OpenProject::Events::PROJECT_UNARCHIVED].each do |event|
OpenProject::Notifications.subscribe(event) do |payload|
Storages::Storage.joins(project_storages: :project)
.where(project_storages: { project_id: payload[:project] }).find_each do |storage|
::Storages::AutomaticallyManagedStorageSyncJob.debounce(storage)
end
end
end

Expand Down

0 comments on commit c70486b

Please sign in to comment.