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

evaluate changes on journal creation only for supported associations

ulfertsbb33e3939525
diff --git a/app/services/journals/create_service.rb b/app/services/journals/create_service.rb
index 3309da5dbbd..6c5758cca8c 100644
--- a/app/services/journals/create_service.rb
+++ b/app/services/journals/create_service.rb
@@ -229,6 +229,14 @@ module Journals
def relation_modifications_sql(predecessor)
relations = []
+ for_supported_associations do |association|
+ relations << association_modifications_sql(association, predecessor)
+ end
+
+ relations
+ end
+
+ def for_supported_associations
associations = {
attachable?: :attachable,
customizable?: :customizable,
@@ -238,11 +246,9 @@ module Journals
associations.each do |is_associated, association|
if journable.respond_to?(is_associated)
- relations << association_modifications_sql(association, predecessor)
+ yield association
end
end
-
- relations
end
def association_modifications_sql(association, predecessor)
@@ -612,28 +618,23 @@ module Journals
end
def select_changed_sql
- <<~SQL
+ sql = <<~SQL
SELECT
*
FROM
(#{data_changes_sql}) data_changes
- FULL JOIN
- (#{customizable_changes_sql}) customizable_changes
- ON
- customizable_changes.journable_id = data_changes.journable_id
- FULL JOIN
- (#{attachable_changes_sql}) attachable_changes
- ON
- attachable_changes.journable_id = data_changes.journable_id
- FULL JOIN
- (#{storable_changes_sql}) storable_changes
- ON
- storable_changes.journable_id = data_changes.journable_id
- FULL JOIN
- (#{agenda_itemable_changes_sql}) agenda_itemable_changes
- ON
- agenda_itemable_changes.journable_id = data_changes.journable_id
SQL
+
+ for_supported_associations do |association|
+ sql += <<~SQL
+ FULL JOIN
+ (#{send(:"#{association}_changes_sql")}) #{association}_changes
+ ON
+ #{association}_changes.journable_id = data_changes.journable_id
+ SQL
+ end
+
+ sql
end
def attachable_changes_sql