Skip to content

Commit

Permalink
Merge pull request #6091 from avalonmediasystem/extra_saves
Browse files Browse the repository at this point in the history
Remove redundant saves and other redundant costly setup
  • Loading branch information
cjcolvar authored Nov 5, 2024
2 parents d2df1bc + e1c6bde commit 681e2ee
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ GIT

GIT
remote: https://github.com/avalonmediasystem/avalon-workflow.git
revision: 1c188a2be9255ebd8b0b959f04dbf5f888715fb9
tag: avalon-r6.5
revision: df6cdec6fb0ed69b33f843a18ead18979a6c87d3
branch: failed_update_setup_edit
specs:
avalon-workflow (0.0.3)

Expand Down
19 changes: 2 additions & 17 deletions app/models/access_control_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
6 changes: 6 additions & 0 deletions app/models/concerns/media_object_mods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,19 @@ 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!
descMetadata.remove_empty_nodes!
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
30 changes: 0 additions & 30 deletions app/models/preview_step.rb

This file was deleted.

3 changes: 1 addition & 2 deletions app/models/resource_description_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions app/models/structure_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions config/initializers/active_fedora_general.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 681e2ee

Please sign in to comment.