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 loading aggregated journals repeatedly when patching

ulfertse14679d0b3a0
diff --git a/app/models/journal/aggregated_journal.rb b/app/models/journal/aggregated_journal.rb
index 0761d368498..a1955ea6d66 100644
--- a/app/models/journal/aggregated_journal.rb
+++ b/app/models/journal/aggregated_journal.rb
@@ -57,14 +57,6 @@ class Journal::AggregatedJournal
raw ? Journal::AggregatedJournal.new(raw) : nil
end
- # 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 database
def reloaded
- self.class.with_notes_id(notes_id)
+ self.class.containing_journal(journal)
end
def user
diff --git a/lib/api/v3/activities/activities_api.rb b/lib/api/v3/activities/activities_api.rb
index 7648a4c0991..bba14b2012b 100644
--- a/lib/api/v3/activities/activities_api.rb
+++ b/lib/api/v3/activities/activities_api.rb
@@ -35,14 +35,18 @@ module API
resources :activities do
route_param :id, type: Integer, desc: 'Activity ID' do
after_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) do
raise API::Errors::NotFound
end
end
helpers do
+ def aggregated_activity(activity)
+ Journal::AggregatedJournal.containing_journal(activity)
+ end
+
def save_activity(activity)
unless activity.save
fail ::API::Errors::ErrorBase.create_and_merge_errors(activity.errors)
@@ -55,7 +59,7 @@ module API
end
get do
- ActivityRepresenter.new(@activity, current_user: current_user)
+ ActivityRepresenter.new(aggregated_activity(@activity), current_user: current_user)
end
params do
@@ -64,12 +68,11 @@ module API
patch 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)
end
end
end