From d3c275ccdd3734e9494a9ab5758a1eafb5bb6096 Mon Sep 17 00:00:00 2001 From: cjcolvar Date: Tue, 29 Oct 2024 15:32:56 -0400 Subject: [PATCH 1/5] Remove redundant saves and other redundant costly setup Co-authored-by: Mason Ballengee --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/models/access_control_step.rb | 19 ++-------------- app/models/preview_step.rb | 30 ------------------------- app/models/resource_description_step.rb | 3 +-- app/models/structure_step.rb | 3 +-- 6 files changed, 7 insertions(+), 54 deletions(-) delete mode 100644 app/models/preview_step.rb diff --git a/Gemfile b/Gemfile index db48b039e2..a59267e5a9 100644 --- a/Gemfile +++ b/Gemfile @@ -63,7 +63,7 @@ gem 'samvera-persona', git: 'https://github.com/samvera-labs/samvera-persona.git gem 'speedy-af', git: 'https://github.com/samvera-labs/speedy_af.git', branch: 'empty_reflection' # Avalon Components -gem 'avalon-workflow', git: "https://github.com/avalonmediasystem/avalon-workflow.git", tag: 'avalon-r6.5' +gem 'avalon-workflow', git: "https://github.com/avalonmediasystem/avalon-workflow.git", branch: 'failed_update_setup_edit' # Authentication & Authorization gem 'devise', '~> 4.8' diff --git a/Gemfile.lock b/Gemfile.lock index aaeb28f0f6..3f458ae2a6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -26,8 +26,8 @@ GIT GIT remote: https://github.com/avalonmediasystem/avalon-workflow.git - revision: 1c188a2be9255ebd8b0b959f04dbf5f888715fb9 - tag: avalon-r6.5 + revision: 1562c1901df94c1e4912bdbdc51b910ff250a2d0 + branch: failed_update_setup_edit specs: avalon-workflow (0.0.3) diff --git a/app/models/access_control_step.rb b/app/models/access_control_step.rb index 4a4ad6f582..6a888eb547 100644 --- a/app/models/access_control_step.rb +++ b/app/models/access_control_step.rb @@ -90,8 +90,8 @@ def execute context end if context['remove_lease'].present? limited_access_submit = true - lease = Lease.find( context['remove_lease'] ) - media_object.governing_policies.delete( lease ) + lease = Lease.find(context['remove_lease']) + media_object.governing_policies.delete(lease) lease.destroy end @@ -108,21 +108,6 @@ def execute context end end - media_object.save! - - #Setup these values in the context because the edit partial is being rendered without running the controller's #edit (VOV-2978) - media_object.reload - context[:users] = media_object.read_users - context[:groups] = media_object.read_groups - context[:virtual_groups] = media_object.virtual_read_groups - context[:ip_groups] = media_object.ip_read_groups - context[:group_leases] = media_object.leases('local') - context[:user_leases] = media_object.leases('user') - context[:virtual_leases] = media_object.leases('external') - context[:ip_leases] = media_object.leases('ip') - context[:addable_groups] = Admin::Group.non_system_groups.reject { |g| context[:groups].include? g.name } - context[:addable_courses] = Course.all.reject { |c| context[:virtual_groups].include? c.context_id } - context[:lending_period] = media_object.lending_period context end diff --git a/app/models/preview_step.rb b/app/models/preview_step.rb deleted file mode 100644 index e9ab8f807c..0000000000 --- a/app/models/preview_step.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2011-2024, The Trustees of Indiana University and Northwestern -# University. Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. -# --- END LICENSE_HEADER BLOCK --- - -class PreviewStep < Avalon::Workflow::BasicStep - def initialize(step = 'preview', - title = "Preview and publish", - summary = "Release the item for use", - template = 'preview') - super - end - - def execute context - media_object = context[:media_object] - # Publish the media object - media_object.avalon_publisher = context[:user] - media_object.save - context - end -end diff --git a/app/models/resource_description_step.rb b/app/models/resource_description_step.rb index d357f11562..57010c6091 100644 --- a/app/models/resource_description_step.rb +++ b/app/models/resource_description_step.rb @@ -24,9 +24,8 @@ def execute context media_object.descMetadata.populate_from_catalog!(context[:media_object_params][:bibliographic_id][:id],context[:media_object_params][:bibliographic_id][:source]) else media_object.permalink = context[:media_object_params].delete(:permalink) - media_object.update_attributes(context[:media_object_params]) + media_object.assign_attributes(context[:media_object_params]) end - media_object.save context end end diff --git a/app/models/structure_step.rb b/app/models/structure_step.rb index aa35b0935f..2475a75817 100644 --- a/app/models/structure_step.rb +++ b/app/models/structure_step.rb @@ -19,9 +19,8 @@ def initialize(step = 'structure', title = "Structure", summary = "Organization def execute context media_object = context[:media_object] - if ! context[:master_file_ids].nil? + if context[:master_file_ids].present? media_object.section_ids = context[:master_file_ids] - media_object.save end context end From 5e445d22b73c389b742dd2be8e93dd8f8aad75fd Mon Sep 17 00:00:00 2001 From: cjcolvar Date: Tue, 29 Oct 2024 16:25:11 -0400 Subject: [PATCH 2/5] Update avalon-workflow --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3f458ae2a6..9c39bcdd27 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -26,7 +26,7 @@ GIT GIT remote: https://github.com/avalonmediasystem/avalon-workflow.git - revision: 1562c1901df94c1e4912bdbdc51b910ff250a2d0 + revision: df6cdec6fb0ed69b33f843a18ead18979a6c87d3 branch: failed_update_setup_edit specs: avalon-workflow (0.0.3) From 52a03e9479b04c77af4d36cf03e0d181f485ad0d Mon Sep 17 00:00:00 2001 From: cjcolvar Date: Wed, 30 Oct 2024 17:16:03 -0400 Subject: [PATCH 3/5] Avoid modifying MODS when nothing has changed in the content --- app/models/concerns/media_object_mods.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/concerns/media_object_mods.rb b/app/models/concerns/media_object_mods.rb index 17261d173a..96698cc5e3 100644 --- a/app/models/concerns/media_object_mods.rb +++ b/app/models/concerns/media_object_mods.rb @@ -488,6 +488,7 @@ def record_identifier=(value) # Put the pieces into the right order and validate to make sure that there are no # syntactic errors def normalize_desc_metadata! + return unless descMetadata.content_changed? descMetadata.ensure_identifier_exists!(self.uri) descMetadata.update_change_date! descMetadata.reorder_elements! From 88680da46f8c4568881948a150e295d94011a504 Mon Sep 17 00:00:00 2001 From: cjcolvar Date: Wed, 30 Oct 2024 17:16:58 -0400 Subject: [PATCH 4/5] Don't mark type as dirty if class type is empty This avoids a save of the file metadata when nothing has changed. --- config/initializers/active_fedora_general.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/config/initializers/active_fedora_general.rb b/config/initializers/active_fedora_general.rb index 928f69c825..968cb63305 100644 --- a/config/initializers/active_fedora_general.rb +++ b/config/initializers/active_fedora_general.rb @@ -196,3 +196,16 @@ def delete_record(record) owner.save end end + +ActiveFedora::WithMetadata::MetadataNode.class_eval do + # @param file [ActiveFedora::File] + def initialize(file) + @file = file + super(file.uri, ldp_source.graph) + # Override the guard to ensure there is a type present in the class + return unless self.class.type.present? && !type.include?(self.class.type) + attribute_will_change!(:type) if type.present? + # Workaround for https://github.com/ActiveTriples/ActiveTriples/issues/123 + get_values(:type) << self.class.type + end +end From e1c6bde1dfd94cbf8063b2b7ea0249bedcd2f018 Mon Sep 17 00:00:00 2001 From: cjcolvar Date: Tue, 5 Nov 2024 13:36:29 -0500 Subject: [PATCH 5/5] Mark content as changed when deleting nodes instead of only when added because sometimes all values are removed --- app/models/concerns/media_object_mods.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/concerns/media_object_mods.rb b/app/models/concerns/media_object_mods.rb index 96698cc5e3..44bca2b5cd 100644 --- a/app/models/concerns/media_object_mods.rb +++ b/app/models/concerns/media_object_mods.rb @@ -496,6 +496,11 @@ def normalize_desc_metadata! end def delete_all_values(*field_name) + # Manually mark the content as changed when deleteing values. + # Adding values causes calls into active_fedora-datastreams which markes the content as changed. + # The ng_xml_will_change! call here covers the case when all values are deleted and none are added back. + # This also markes the content as changed. + descMetadata.ng_xml_will_change! descMetadata.find_by_terms(*field_name).each &:remove end end