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
avoid loading aggregated journals repeatedly when patching
ulfertse14679d0b3a0
diff --git a/app/models/journal/aggregated_journal.rb b/app/models/journal/aggregated_journal.rbindex 0761d368498..a1955ea6d66 100644--- a/app/models/journal/aggregated_journal.rb+++ b/app/models/journal/aggregated_journal.rb@@ -57,14 +57,6 @@ class Journal::AggregatedJournalraw ? Journal::AggregatedJournal.new(raw) : nilend- # Returns the aggregated journal that contains the vanilla/pure journal with the specified id.- def with_notes_id(notes_id)- # We need to limit the journal aggregation as soon as possible for performance reasons.- # Therefore we have to provide the notes_id to the aggregation on top of it being used- # in the where clause to pick the desired AggregatedJournal.- containing_journal(Journal.find(notes_id))- end-### The +journable+ parameter allows to filter for aggregated journals of a given journable.#@@ -218,7 +210,7 @@ class Journal::AggregatedJournal# returns an instance of this class that is reloaded from the databasedef reloaded- self.class.with_notes_id(notes_id)+ self.class.containing_journal(journal)enddef userdiff --git a/lib/api/v3/activities/activities_api.rb b/lib/api/v3/activities/activities_api.rbindex 7648a4c0991..bba14b2012b 100644--- a/lib/api/v3/activities/activities_api.rb+++ b/lib/api/v3/activities/activities_api.rb@@ -35,14 +35,18 @@ module APIresources :activities doroute_param :id, type: Integer, desc: 'Activity ID' doafter_validation do- @activity = Journal::AggregatedJournal.with_notes_id(declared_params[:id])+ @activity = Journal.find(declared_params[:id])- authorize_by_with_raise @activity&.journable&.visible?(current_user) do+ authorize_by_with_raise @activity.journable.visible?(current_user) doraise API::Errors::NotFoundendendhelpers do+ def aggregated_activity(activity)+ Journal::AggregatedJournal.containing_journal(activity)+ end+def save_activity(activity)unless activity.savefail ::API::Errors::ErrorBase.create_and_merge_errors(activity.errors)@@ -55,7 +59,7 @@ module APIendget do- ActivityRepresenter.new(@activity, current_user: current_user)+ ActivityRepresenter.new(aggregated_activity(@activity), current_user: current_user)endparams do@@ -64,12 +68,11 @@ module APIpatch do# TODO: Write a journal update service- editable_activity = Journal.find(@activity.notes_id)- authorize_edit_own(editable_activity)- editable_activity.notes = declared_params[:comment]- save_activity(editable_activity)+ authorize_edit_own(@activity)+ @activity.notes = declared_params[:comment]+ save_activity(@activity)- ActivityRepresenter.new(@activity.reloaded, current_user: current_user)+ ActivityRepresenter.new(aggregated_activity(@activity), current_user: current_user)endendend